Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for #[Deprecated()] annotation #81

Open
DeyV opened this issue Dec 13, 2022 · 4 comments
Open

Support for #[Deprecated()] annotation #81

DeyV opened this issue Dec 13, 2022 · 4 comments

Comments

@DeyV
Copy link

DeyV commented Dec 13, 2022

phpstorm-stubs use JetBrains\PhpStorm\Deprecated annotation to mark method's, class e.t.c
This annotation allows for more detailed description of the problem and suggested changes.

Other projects use this annotation as well

Can deprecation-rules show it in the same way like @deprecated ?

@cavasinf
Copy link

Could be a nice feature!

The today work around: Double @deprecated and #[Deprecated]

/**
 * @deprecated
 */
#[Deprecated("use createFromDateRange() instead", 'DateHelper::createFromDateRange(%parametersList%)')]
public static function fromDateRangePicker(string $dateRangeFormData): array
{
    return self::createFromDateRange($dateRangeFormData);
}

@cavasinf
Copy link

cavasinf commented Dec 8, 2023

Is it hard to implement @ondrejmirtes?

@ondrejmirtes
Copy link
Member

It's not hard at all. The issue is that this attribute isn't official in any way. Someone might prefer to use a different attribute (like their own class) for this same purpose so we better make sure this system is extensible like other similar extension types in PHPStan: https://phpstan.org/developing-extensions/extension-types

@mglaman
Copy link
Contributor

mglaman commented Jan 10, 2024

Sorry, I hijacked this. The wrong node would be passed in. But using \PHPStan\Analyser\Scope::getFunctionCallStack to find the parent node would allow inspecting the method's attributes in a custom scope resolver.

Old and invalid

I think this would be achievable if `\PHPStan\Rules\Deprecations\DeprecatedScopeHelper` was aware of the node in `\PHPStan\Rules\Deprecations\DeprecatedScopeHelper::isScopeDeprecated`.

A custom deprecated scope resolver could then inspect the node to see if it has the attribute.

The problem is I cannot think of a non-breaking way to introduce a change to \PHPStan\Rules\Deprecations\DeprecatedScopeResolver::isScopeDeprecated

Edit: Passing the node object in would help solve a final problem in mglaman/phpstan-drupal#714 for myself.

I'll propose a PR so we can discuss the code, or just close out the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants