-
Notifications
You must be signed in to change notification settings - Fork 516
Add phpstan-sealed support #4095
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
Conversation
014db69
to
86c6ab1
Compare
86c6ab1
to
7e2ab56
Compare
src/Rules/Classes/SealedRule.php
Outdated
|
||
$errors[] = RuleErrorBuilder::message( | ||
sprintf( | ||
'%s %s is sealed and only permits %s as subtypes, %s given.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this rule, you should implement this extension https://apiref.phpstan.org/2.1.x/PHPStan.Reflection.AllowedSubTypesClassReflectionExtension.html. Which actually make this @phpstan-sealed
tag useful for analysis, and also already checks what you're checking here, through AllowedSubTypesRule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With SealedAllowedSubTypesClassReflectionExtension implemented, this rule can be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, dunno why I forget to remove it ; it's done.
Some issues are related to sealed classes and after this is implemented, it'd be easier to reproduce them and in the end, fix them:
|
9ce9eb4
to
841c855
Compare
The failure seems unrelated to the PR but to fe4bf2c |
This pull request has been marked as ready for review. |
src/Rules/Classes/SealedRule.php
Outdated
|
||
$errors[] = RuleErrorBuilder::message( | ||
sprintf( | ||
'%s %s is sealed and only permits %s as subtypes, %s given.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With SealedAllowedSubTypesClassReflectionExtension implemented, this rule can be deleted.
* @implements Rule<InClassNode> | ||
*/ | ||
#[RegisteredRule(level: 0)] | ||
final class SealedDefinitionClassRule implements Rule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be level 2. That's where PHPDocs are being checked.
Thank you! |
Please submit docs change for "PHPDocs basics" page. |
What should we do about this page https://phpstan.org/developing-extensions/allowed-subtypes now it could be simply done with |
We can put a blue box there explaining there's an easier way, but the extension is still relevant if people want to do it with their custom attributes or other logic. |
No description provided.