Skip to content

Commit 9f1aebf

Browse files
committed
NegationOperatorSpacingSniff: Fixed false positive
1 parent bf3a16a commit 9f1aebf

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

SlevomatCodingStandard/Sniffs/Operators/NegationOperatorSpacingSniff.php

Lines changed: 6 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 SlevomatCodingStandard\Helpers\IdentificatorHelper;
78
use SlevomatCodingStandard\Helpers\SniffSettingsHelper;
89
use SlevomatCodingStandard\Helpers\TokenHelper;
910
use function array_merge;
@@ -68,6 +69,11 @@ public function process(File $phpcsFile, $pointer): void
6869
return;
6970
}
7071

72+
$possibleVariableStartPointer = IdentificatorHelper::findStartPointer($phpcsFile, $previousEffective);
73+
if ($possibleVariableStartPointer !== null) {
74+
return;
75+
}
76+
7177
$whitespacePointer = $pointer + 1;
7278

7379
$numberOfSpaces = $tokens[$whitespacePointer]['code'] !== T_WHITESPACE ? 0 : strlen($tokens[$whitespacePointer]['content']);

tests/Sniffs/Operators/data/negationOperatorSpacingNoErrors.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ function(){yield -$b;};
104104
$a = [$a, -$b];
105105
$a = $a[-$b];
106106
$a = $a ? -$b : -$b;
107+
$a = (int) $b->{'foo'} - (int) $b->{'bar'};

0 commit comments

Comments
 (0)