Skip to content

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

Merged
merged 5 commits into from
Jul 15, 2025
Merged

Conversation

VincentLanglet
Copy link
Contributor

No description provided.

@VincentLanglet VincentLanglet force-pushed the phpstan-sealed branch 5 times, most recently from 014db69 to 86c6ab1 Compare July 13, 2025 20:04

$errors[] = RuleErrorBuilder::message(
sprintf(
'%s %s is sealed and only permits %s as subtypes, %s given.',
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@ondrejmirtes
Copy link
Member

@VincentLanglet
Copy link
Contributor Author

The failure seems unrelated to the PR but to fe4bf2c

@VincentLanglet VincentLanglet marked this pull request as ready for review July 13, 2025 21:18
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.


$errors[] = RuleErrorBuilder::message(
sprintf(
'%s %s is sealed and only permits %s as subtypes, %s given.',
Copy link
Member

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
Copy link
Member

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.

@ondrejmirtes ondrejmirtes merged commit ae7fd77 into phpstan:2.1.x Jul 15, 2025
101 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@ondrejmirtes
Copy link
Member

Please submit docs change for "PHPDocs basics" page.

@VincentLanglet
Copy link
Contributor Author

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 @phpstan-sealed ?

@ondrejmirtes
Copy link
Member

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.

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.

4 participants