Skip to content

Commit 80e61a0

Browse files
committed
RequireCombinedAssignmentOperatorSniff: Fixed false positive
1 parent 287ac33 commit 80e61a0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

SlevomatCodingStandard/Sniffs/Operators/RequireCombinedAssignmentOperatorSniff.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHP_CodeSniffer\Files\File;
66
use PHP_CodeSniffer\Sniffs\Sniff;
7+
use PHP_CodeSniffer\Util\Tokens;
78
use SlevomatCodingStandard\Helpers\IdentificatorHelper;
89
use SlevomatCodingStandard\Helpers\TokenHelper;
910
use function array_key_exists;
@@ -18,6 +19,7 @@
1819
use const T_MULTIPLY;
1920
use const T_PLUS;
2021
use const T_POW;
22+
use const T_SEMICOLON;
2123
use const T_SL;
2224
use const T_SR;
2325
use const T_STRING_CONCAT;
@@ -90,6 +92,11 @@ public function process(File $phpcsFile, $equalPointer): void
9092
return;
9193
}
9294

95+
$semicolonPointer = TokenHelper::findNext($phpcsFile, T_SEMICOLON, $equalPointer + 1);
96+
if (TokenHelper::findNext($phpcsFile, Tokens::$operators, $operatorPointer + 1, $semicolonPointer) !== null) {
97+
return;
98+
}
99+
93100
$fix = $phpcsFile->addFixableError(
94101
sprintf('Use "%s" operator instead of "=" and "%s".', $operators[$tokens[$operatorPointer]['code']], $tokens[$operatorPointer]['content']),
95102
$equalPointer,

tests/Sniffs/Operators/data/requireCombinedAssignmentOperatorNoErrors.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,10 @@ public function shortList($array)
3333
[$a, $b, $c, $d, $e] = $array + range(0, 4);
3434
}
3535

36+
public function moreOperators($a, $b, $c)
37+
{
38+
$a = $a / $b / $c;
39+
}
40+
3641
}
3742

0 commit comments

Comments
 (0)