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

PSR2/SwitchDeclaration: bug fix when determining terminating statement #3551

Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Feb 25, 2022

Trailing comments within control structures nested within a switch case would break the determination of whether or not there is a terminating statement within the nested control structure.

Making the findNestedTerminator() method look for non-empty instead of non-whitespace tokens fixes that and shouldn't break the TerminatingComment check as that has it's own check whether the last token in the case statement is a comment.

Includes unit tests.

Fixes #3550

Trailing comments within control structures nested within a switch case would break the determination of whether or not there is a terminating statement within the nested control structure.

Making the `findNestedTerminator()` method look for non-empty instead of non-whitespace tokens fixes that and shouldn't break the `TerminatingComment` check as that has it's own check whether the last token in the case statement is a comment.

Includes unit tests.

Fixes 3550
@zorac
Copy link

zorac commented Feb 25, 2022

I've tested this with a number of variations on my original test case, and it works perfectly. Many thanks for the speedy patch!

@jrfnl
Copy link
Contributor Author

jrfnl commented Feb 25, 2022

@zorac Thanks for testing & confirming the fix!

@gsherwood gsherwood added this to the 3.7.0 milestone Feb 27, 2022
gsherwood added a commit that referenced this pull request Mar 18, 2022
@gsherwood gsherwood merged commit 82cfe20 into squizlabs:master Mar 18, 2022
@gsherwood
Copy link
Member

Thanks for the fix

@jrfnl jrfnl deleted the feature/3550-psr2-switchstatement-bugfix branch March 18, 2022 09:07
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.

False positive from PSR2.ControlStructures.SwitchDeclaration.TerminatingComment when using trailing comment
3 participants