Commit 407724a
committed
Generic/RequireExplicitBooleanOperatorPrecedence: remove
unreachable condition
This commit 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:
```php
match (true) {
$a || ($b && $c) => true,
};
```
I believe the false positive was actually caused by a bug in
`File::findStartOfStatement()`. This bug was then fixed in
PHPCSStandards@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 to `false` and the sniff
bails before reaching the removed condition.
Including `Tokens::$blockOpeners` in
`RequireExplicitBooleanOperatorPrecedenceSniff::$searchTargets` was
necessary only for the removed condition, so it was removed as well.1 parent 2e3c58b commit 407724a
File tree
1 file changed
+1
-8
lines changed- src/Standards/Generic/Sniffs/CodeAnalysis
1 file changed
+1
-8
lines changedLines changed: 1 addition & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
| |||
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | 104 | | |
112 | 105 | | |
113 | 106 | | |
| |||
0 commit comments