Skip to content

Commit 9cefbf1

Browse files
committed
EarlyExitSniff: fixed notice
1 parent 2b5a5a2 commit 9cefbf1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

SlevomatCodingStandard/Sniffs/ControlStructures/EarlyExitSniff.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,11 @@ private function getAllConditionsPointers(\PHP_CodeSniffer\Files\File $phpcsFile
495495
}
496496

497497
$currentConditionPointer = TokenHelper::findNextEffective($phpcsFile, $tokens[$conditionPointer]['scope_closer'] + 1);
498-
while (in_array($tokens[$currentConditionPointer]['code'], [T_ELSEIF, T_ELSE], true)) {
499-
$conditionsPointers[] = $currentConditionPointer;
500-
$currentConditionPointer = TokenHelper::findNextEffective($phpcsFile, $tokens[$currentConditionPointer]['scope_closer'] + 1);
498+
if ($currentConditionPointer !== null) {
499+
while (in_array($tokens[$currentConditionPointer]['code'], [T_ELSEIF, T_ELSE], true)) {
500+
$conditionsPointers[] = $currentConditionPointer;
501+
$currentConditionPointer = TokenHelper::findNextEffective($phpcsFile, $tokens[$currentConditionPointer]['scope_closer'] + 1);
502+
}
501503
}
502504
}
503505

tests/Sniffs/ControlStructures/data/earlyExitNoErrors.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,10 @@ function allConditionsWithEarlyExitButCodeAfter($dateTime) {
173173

174174
doSomething();
175175
}
176+
177+
// Code in the end of file
178+
if (!empty($_SERVER['argv'])) {
179+
something();
180+
} elseif (PHP_SAPI !== 'cli') {
181+
somethingElse();
182+
}

0 commit comments

Comments
 (0)