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

Detect override of deprecated property #90

Open
wants to merge 5 commits into
base: 1.1.x
Choose a base branch
from

Conversation

Khartir
Copy link
Contributor

@Khartir Khartir commented Mar 17, 2023

Closes #82

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We shouldn't report this for private properties that are marked as @deprecated.
  2. We should also have the same rule for methods and constants.
  3. These new rules have to be registered in bleedingEdge only. Example here: https://github.com/phpstan/phpstan-doctrine/blob/62bd362b432fe29e175168689510ddd927b698f8/rules.neon#L27-L29

@Khartir Khartir force-pushed the overridden-property branch from a5d3011 to 7ba6d2f Compare March 31, 2023 09:59
@Khartir Khartir requested a review from ondrejmirtes March 31, 2023 10:02
@Khartir Khartir force-pushed the overridden-property branch from 7ba6d2f to 2226d83 Compare March 31, 2023 10:08

$parents = $class->getParents();

$name = (string) $node->consts[0]->name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should go through all the constants, not just the first one.


$class = $scope->getClassReflection();

$parents = $class->getParents();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't go through all the parents. This would break the @deprecated / @not-deprecated behaviour. Please read about it and write a test: https://phpstan.org/writing-php-code/phpdocs-basics#deprecations

It's sufficient to ask for the property in the first parent class if there's one.

You should also look into interfaces.


$class = $scope->getClassReflection();

$parents = $class->getParents();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dtto with parents

return [];
}

return [sprintf(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the more modern approach with RuleErrorBuilder instead of just returning a string.

@ondrejmirtes
Copy link
Member

Hi, I can't review this because you need to rebase your commits on top of 1.1.x. Your branch includes commits from 1.2.x which is unwanted.

@Khartir Khartir force-pushed the overridden-property branch from 5ec6592 to daf5f98 Compare January 8, 2024 10:03
@Khartir
Copy link
Contributor Author

Khartir commented Jan 8, 2024

Sorry about that, after it took me so long to get back to this, I just updated to the most recent branch.

@Khartir Khartir force-pushed the overridden-property branch from daf5f98 to b924bc4 Compare January 9, 2024 06:55
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

Successfully merging this pull request may close these issues.

Add detection of overridden deprecated properties
2 participants