Skip to content

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

Merged
gsherwood merged 1 commit intosquizlabs:masterfrom
jrfnl:feature/3550-psr2-switchstatement-bugfix
Mar 18, 2022
Merged

PSR2/SwitchDeclaration: bug fix when determining terminating statement#3551
gsherwood merged 1 commit intosquizlabs:masterfrom
jrfnl:feature/3550-psr2-switchstatement-bugfix

Conversation

@jrfnl
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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