Skip to content

Commit af1aeb9

Browse files
committed
ControlStructureSpacingSniff: Fixed internal error
1 parent a1f951a commit af1aeb9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

SlevomatCodingStandard/Sniffs/ControlStructures/ControlStructureSpacingSniff.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ private function checkLinesAfter(File $phpcsFile, int $controlStructurePointer):
210210
$controlStructureEndPointer = $this->findControlStructureEnd($phpcsFile, $controlStructurePointer);
211211
$pointerAfter = TokenHelper::findNextExcluding($phpcsFile, T_WHITESPACE, $controlStructureEndPointer + 1);
212212

213+
if ($pointerAfter === null) {
214+
return;
215+
}
216+
213217
$isLastControlStructure = in_array($tokens[$pointerAfter]['code'], [T_CLOSE_CURLY_BRACKET, T_CASE, T_DEFAULT], true);
214218

215219
$requiredLinesCountAfter = SniffSettingsHelper::normalizeInteger($isLastControlStructure ? $this->linesCountAfterLastControlStructure : $this->linesCountAroundControlStructure);
@@ -251,6 +255,10 @@ private function findControlStructureEnd(File $phpcsFile, int $controlStructureP
251255
$controlStructureEndPointer = $tokens[$controlStructurePointer]['scope_closer'];
252256
do {
253257
$nextPointer = TokenHelper::findNextEffective($phpcsFile, $controlStructureEndPointer + 1);
258+
if ($nextPointer === null) {
259+
return $controlStructureEndPointer;
260+
}
261+
254262
if ($tokens[$nextPointer]['code'] === T_ELSE) {
255263
return $tokens[$nextPointer]['scope_closer'];
256264
}

tests/Sniffs/ControlStructures/data/controlStructureSpacingWithDefaultSettingsNoErrors.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,7 @@ function () {
103103

104104
return yield from $array;
105105
};
106+
107+
if (true) {
108+
109+
}

0 commit comments

Comments
 (0)