Skip to content

Commit 8559df0

Browse files
committed
UselessParenthesesSniff: Fixed false positive
1 parent 74d026b commit 8559df0

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ private function checkParenthesesAroundConditionInTernaryOperator(File $phpcsFil
134134
return;
135135
}
136136

137+
if (in_array($tokens[$pointerBeforeParenthesisOpener]['code'], Tokens::$booleanOperators, true)) {
138+
return;
139+
}
140+
137141
if ($this->ignoreComplexTernaryConditions) {
138142
if (TokenHelper::findNext($phpcsFile, Tokens::$booleanOperators, $parenthesisOpenerPointer + 1, $parenthesisCloserPointer) !== null) {
139143
return;

tests/Sniffs/PHP/data/uselessParenthesesNoErrors.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,5 @@ function () {
9393
$a = $b + (100 - $c);
9494

9595
$a = 'a' . '/' . (32 - ($b * 8));
96+
97+
$var = $foo && ($bar > 0 || $baz > 0) ? true : false;

0 commit comments

Comments
 (0)