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

Squiz/ClassDeclaration: allow for function attributes #825

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Feb 16, 2025

Description

The Squiz.Classes.ClassDeclaration sniff checks the number of blank lines after a class closing brace to be exactly one blank line.

To prevent conflicts with other sniffs checking blank lines before function declarations, it bows out when the next thing after the class declaration is a function declaration and defers to the function declaration sniff to handle the "blank lines before function" check. See squizlabs/PHP_CodeSniffer#2033 for historic context.

However, the above "bowing out" breaks when a function after a class has PHP 8.0+ attributes attached to it and the sniff would still throw the NewlinesAfterCloseBrace error.

Fixed now.

Includes tests.

Note: the new "errors" caused by the new tests are for the MultipleClasses code, which is unrelated to this fix and valid.

Suggested changelog entry

Squiz.Classes.ClassDeclaration: correctly bow out from checking the "lines after class" when the next thing is a function with attribute(s).

Related issues/external references

Related to #152

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

The `Squiz.Classes.ClassDeclaration` sniff checks the number of blank lines _after_ a class closing brace to be exactly one blank line.

To prevent conflicts with other sniffs checking blank lines before function declarations, it bows out when the next thing after the class declaration is a function declaration and defers to the function declaration sniff to handle the "blank lines before function" check.
See squizlabs/PHP_CodeSniffer 2033 for historic context.

However, the above "bowing out" breaks when a function after a class has PHP 8.0+ attributes attached to it and the sniff would still the `NewlinesAfterCloseBrace` error.

Fixed now.

Includes tests.

Note: the new "errors" caused by the new tests are for the `MultipleClasses` code, which is unrelated to this fix and valid.
@jrfnl jrfnl force-pushed the feature/squiz-classdeclaration-php-80-attributes branch from 16047ce to debbff4 Compare February 16, 2025 13:55
@jrfnl
Copy link
Member Author

jrfnl commented Feb 16, 2025

Force push was to fix a minor typo in the test case file.

@jrfnl jrfnl removed this from the 3.12.0 milestone Mar 3, 2025
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.

1 participant