Skip to content

Commit de61dd2

Browse files
committed
RequireNullCoalesceOperatorSniff: Fixed false positives
1 parent 4f955a3 commit de61dd2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

SlevomatCodingStandard/Sniffs/ControlStructures/RequireNullCoalesceOperatorSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function checkIsset(File $phpcsFile, int $issetPointer): void
6767
return;
6868
}
6969

70+
if (in_array($tokens[$previousPointer]['code'], Tokens::$booleanOperators, true)) {
71+
return;
72+
}
73+
7074
$openParenthesisPointer = TokenHelper::findNextEffective($phpcsFile, $issetPointer + 1);
7175
$closeParenthesisPointer = $tokens[$openParenthesisPointer]['parenthesis_closer'];
7276

tests/Sniffs/ControlStructures/data/requireNullCoalesceOperatorNoErrors.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@
3939
$q = $r !== null && $s !== null
4040
? $s
4141
: '';
42+
43+
$t = $t && isset($v) ? $v : null;
44+
$t = $t || isset($v) ? $v : null;
45+
$t = $t and isset($v) ? $v : null;
46+
$t = $t or isset($v) ? $v : null;
47+
$t = $t xor isset($v) ? $v : null;

0 commit comments

Comments
 (0)