Skip to content

Conversation

@rodrigoprimo
Copy link
Collaborator

Before this PR, AbstractClassRestrictionsSniff::is_targetted_token() would name an anonymous class as "\class" or "\readonly" (in the case of readonly anonymous classes). While this would not cause false positives as it is not possible for a class to be named "class" or "readonly", it is not the correct behavior.

This commit improves how this method handles anonymous classes by returning false early, as those classes don't have a name.

Includes tests for readonly anonymous classes. It was not necessary to include more tests for normal anonymous classes, as the existing tests are already enough.

Before this commit, `AbstractClassRestrictionsSniff::is_targetted_token()` would name an anonymous class as "\class" or "\readonly" (in the case of readonly anonymous classes). While this would not cause false positives as it is not possible for a class to be named "class" or "readonly", it is not the correct behavior.

This commit improves how this method handles anonymous classes by returning `false` early as those classes don't have a name.

Includes tests for readonly anonymous classes. It was not necessary to include more tests for normal anonymous classes as the existing tests are already enough.
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Thanks @rodrigoprimo ! Two nitpicky remarks, but nothing blocking.

@jrfnl jrfnl added this to the 3.2.0 milestone Jul 18, 2025
@rodrigoprimo
Copy link
Collaborator Author

Thanks for your review, @jrfnl. I just added your suggestions.

@rodrigoprimo rodrigoprimo force-pushed the abstract-class-restrictions-sniff branch from a34554d to d79af5e Compare July 21, 2025 13:25
@rodrigoprimo
Copy link
Collaborator Author

Force pushed without changes to run the GitHub actions again as they failed with the PHPStan not found error.

@GaryJones GaryJones merged commit e79ca2b into WordPress:develop Jul 21, 2025
41 checks passed
@rodrigoprimo rodrigoprimo deleted the abstract-class-restrictions-sniff branch July 22, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants