Skip to content

Commit 6b08d62

Browse files
donatjkukulich
authored andcommitted
RequireShortTernaryOperatorSniff: Fix token overrun
1 parent 80e61a0 commit 6b08d62

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

SlevomatCodingStandard/Sniffs/ControlStructures/RequireShortTernaryOperatorSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use const T_CLOSE_PARENTHESIS;
1515
use const T_CLOSE_SHORT_ARRAY;
1616
use const T_CLOSE_SQUARE_BRACKET;
17+
use const T_CLOSE_TAG;
1718
use const T_COALESCE;
1819
use const T_COMMA;
1920
use const T_DOUBLE_ARROW;
@@ -55,7 +56,7 @@ public function process(File $phpcsFile, $inlineThenPointer): void
5556

5657
$inlineElseEndPointer = $inlineElsePointer + 1;
5758
while (true) {
58-
if (in_array($tokens[$inlineElseEndPointer]['code'], [T_SEMICOLON, T_COMMA, T_DOUBLE_ARROW, T_CLOSE_SHORT_ARRAY, T_COALESCE], true)) {
59+
if (in_array($tokens[$inlineElseEndPointer]['code'], [T_SEMICOLON, T_COMMA, T_DOUBLE_ARROW, T_CLOSE_SHORT_ARRAY, T_COALESCE, T_CLOSE_TAG], true)) {
5960
break;
6061
}
6162

tests/Sniffs/ControlStructures/RequireShortTernaryOperatorSniffTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@ public function testErrors(): void
5050
self::assertAllFixedInFile($report);
5151
}
5252

53+
public function testNoErrorRecurrence(): void
54+
{
55+
$report = self::checkFile(__DIR__ . '/data/requireShortTernaryOperatorCloseTag.php', [
56+
'lineLengthLimit' => 120,
57+
]);
58+
self::assertNoSniffErrorInFile($report);
59+
}
60+
5361
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?= $this->title ? "{$this->title} - " : '' ?>foo<?= 'foo' ?>

0 commit comments

Comments
 (0)