Skip to content

Commit

Permalink
fix(SingleLineThrowFixer): fixer goes out of range on close tag (#7369)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum committed Oct 11, 2023
1 parent d03e57e commit 0607649
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/FunctionNotation/SingleLineThrowFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void

$endCandidateIndex = $tokens->getNextMeaningfulToken($index);

while (!$tokens[$endCandidateIndex]->equalsAny([')', ']', ',', ';'])) {
while (!$tokens[$endCandidateIndex]->equalsAny([')', ']', ',', ';', [T_CLOSE_TAG]])) {
$blockType = Tokens::detectBlockType($tokens[$endCandidateIndex]);

if (null !== $blockType) {
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixer/FunctionNotation/SingleLineThrowFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ function
}
;',
];

yield [
'<?php throw new Exception("Foo.", 0)?>',
'<?php throw new Exception(
"Foo.",
0
)?>',
];
}

/**
Expand Down

0 comments on commit 0607649

Please sign in to comment.