Generic/ArbitraryParenthesesSpacing: improve handling of switch-case scope closers #296
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Follow up on squizlabs/PHP_CodeSniffer#2826 which was fixed via squizlabs/PHP_CodeSniffer#2876.
The sniff explicitly only intends to handle arbitrary parentheses and tries to avoid clashes with sniffs handling the parentheses spacing of function calls and language construct invocations.
This is done by the sniff bowing out early when the token before the open parenthesis is a token which can be used in a (variable) function call or one of a select list of reserved keywords.
The previous PR tweaked the "bowing out" to allow the sniff to operate on arbitrary parentheses which directly follow the close curly brace of a a previous scope.
The additional condition added was, however, not limited to
T_CLOSE_CURLY_BRACKET
tokens.This has led to a new false positive: When a
die()
/exit()
is used within aswitch-case
statement, thedie
/exit
keyword will be regarded as a scope closer for thecase
statement, in which case, the parentheses for thedie
/exit
would now be treated as arbitrary instead of as belonging to thedie
/exit
keyword.This commit fixes this by limiting the previously introduced check for a scope closer to curly braces only.
Includes tests proving the bug and safeguarding the fix.
Suggested changelog entry
switch
case
.Types of changes