Skip to content

Commit 263d3a9

Browse files
committed
UselessParenthesesSniff: Fixed false positive
1 parent b013709 commit 263d3a9

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,14 @@ private function checkParenthesesAroundOperators(File $phpcsFile, int $parenthes
449449
}
450450

451451
$firstOperatorPointer = $operatorsPointers[0];
452-
if (
453-
in_array($tokens[$pointerBeforeParenthesisOpener]['code'], self::OPERATORS, true)
454-
&& self::OPERATOR_GROUPS[$tokens[$firstOperatorPointer]['code']] !== self::OPERATOR_GROUPS[$tokens[$pointerBeforeParenthesisOpener]['code']]
455-
) {
456-
return;
452+
if (in_array($tokens[$pointerBeforeParenthesisOpener]['code'], self::OPERATORS, true)) {
453+
if (self::OPERATOR_GROUPS[$tokens[$firstOperatorPointer]['code']] !== self::OPERATOR_GROUPS[$tokens[$pointerBeforeParenthesisOpener]['code']]) {
454+
return;
455+
}
456+
457+
if ($tokens[$pointerBeforeParenthesisOpener]['code'] === T_MINUS && $tokens[$firstOperatorPointer]['code'] === T_PLUS) {
458+
return;
459+
}
457460
}
458461

459462
$lastOperatorPointer = $operatorsPointers[count($operatorsPointers) - 1];

tests/Sniffs/PHP/data/uselessParenthesesNoErrors.php

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

124124
$hitRatio = (int) round($hitCount / ($loadCount / 100 ?: 1), 1);
125125

126+
$a = 10 + 1 - (5 + 4);
127+
126128
pow(10, -($x + 1));
127129

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

0 commit comments

Comments
 (0)