Conversation

Khartir

Closes #82

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://.com/phpstan/phpstan-doctrine/blob/62bd362b432fe29e175168689510ddd927b698f8/rules.neon#L27-L29

@KhartirKhartir force-pushed the overridden-property branch from a5d3011 to 7ba6d2f Compare March 31, 2023 09:59
@KhartirKhartir requested a review from ondrejmirtes March 31, 2023 10:02
@KhartirKhartir 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

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.

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

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

@KhartirKhartir 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 . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

Add detection of overridden deprecated properties