Skip to content

Commit f9fd126

Browse files
committed
UselessParenthesesSniff: Fixed false positive
1 parent 6e58e31 commit f9fd126

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,11 @@ private function checkParenthesesAroundOperators(File $phpcsFile, int $parenthes
454454
return;
455455
}
456456

457-
if ($tokens[$pointerBeforeParenthesisOpener]['code'] === T_MINUS && $tokens[$firstOperatorPointer]['code'] === T_PLUS) {
457+
if ($tokens[$pointerBeforeParenthesisOpener]['code'] === T_MINUS && in_array($tokens[$firstOperatorPointer]['code'], [T_PLUS, T_MINUS], true)) {
458458
return;
459459
}
460460

461-
if ($tokens[$pointerBeforeParenthesisOpener]['code'] === T_DIVIDE && $tokens[$firstOperatorPointer]['code'] === T_DIVIDE) {
462-
return;
463-
}
464-
465-
if ($tokens[$pointerBeforeParenthesisOpener]['code'] === T_DIVIDE && $tokens[$firstOperatorPointer]['code'] === T_MULTIPLY) {
461+
if ($tokens[$pointerBeforeParenthesisOpener]['code'] === T_DIVIDE && in_array($tokens[$firstOperatorPointer]['code'], [T_DIVIDE, T_MULTIPLY], true)) {
466462
return;
467463
}
468464
}

tests/Sniffs/PHP/data/uselessParenthesesNoErrors.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ function () {
131131

132132
$a = 10 / (5 * 2);
133133

134+
$a = 10 - (5 - 2);
135+
134136
pow(10, -($x + 1));
135137

136138
if (! ($i === $j - 1)) {

0 commit comments

Comments
 (0)