Generic/RequireExplicitBooleanOperatorPrecedence: remove unreachable condition #635
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
This PR reverts the changes to the
Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence
sniff introduced in PHPCSStandards/PHPCSExtra@7b38efb. The sniff's tests remain relevant, so they were preserved.The original commit was added to fix false positives that the sniff was triggering when handling boolean operators inside a match (see PHPCSStandards/PHPCSExtra#271 (review) -1634348864 and PHPCSStandards/PHPCSExtra#271 (comment) ). Example:
I believe the false positive was actually caused by a bug in
File::findStartOfStatement()
. This bug was then fixed in b82438f which rendered the changes to the sniff itself unnecessary and the removed condition unreachable.Before this fix, when processing the code example above,
File::findStartOfStatement()
returned the variable$a
as the start of the statement for the&&
boolean operator. This meant that$previous
would be set to||
, and the removed condition would be needed to ensure the sniff would bail instead of triggering an error.After this fix,
File::findStartOfStatement()
returns$b
as the start of the statement, and then$previous
is set tofalse
. Thus, the sniff bails before reaching the removed condition.Including
Tokens::$blockOpeners
inRequireExplicitBooleanOperatorPrecedenceSniff::$searchTargets
was necessary only for the removed condition, so it was removed as well.cc @TimWolla in case you are available to check this change you are the author of the sniff.
Types of changes
PR checklist