Skip to content

Commit 1136fb9

Browse files
committed
SlevomatCodingStandard.Variables.UnusedVariable: Fixed false positive
1 parent 1071c98 commit 1136fb9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

SlevomatCodingStandard/Sniffs/Variables/UnusedVariableSniff.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use const T_HEREDOC;
4343
use const T_IF;
4444
use const T_INC;
45+
use const T_INLINE_ELSE;
4546
use const T_LIST;
4647
use const T_MINUS_EQUAL;
4748
use const T_MOD_EQUAL;
@@ -464,6 +465,11 @@ private function isUsedInLoopCycle(File $phpcsFile, int $variablePointer, string
464465
continue;
465466
}
466467

468+
$previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $i - 1);
469+
if ($tokens[$previousPointer]['code'] === T_INLINE_ELSE) {
470+
return true;
471+
}
472+
467473
$parenthesisOwnerPointer = $this->findNestedParenthesisWithOwner($phpcsFile, $i);
468474
if (
469475
$parenthesisOwnerPointer !== null

tests/Sniffs/Variables/data/unusedVariableNoErrors.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,10 @@ function ($i) {
434434
function ($i) {
435435
yield ++$i;
436436
};
437+
438+
function () {
439+
$numericIndex = 0;
440+
while (true) {
441+
return null ?: $numericIndex++;
442+
}
443+
};

0 commit comments

Comments
 (0)