Skip to content

Commit

Permalink
bug: SingleLineThrowFixer - Handle throw expression inside block (#6653)
Browse files Browse the repository at this point in the history
Co-authored-by: SpacePossum <[email protected]>
  • Loading branch information
keradus and SpacePossum authored Oct 12, 2022
1 parent 9b070d0 commit cc8d27a
Show file tree
Hide file tree
Showing 2 changed files with 26 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 @@ -78,7 +78,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
$blockType = Tokens::detectBlockType($tokens[$endCandidateIndex]);

if (null !== $blockType) {
if (Tokens::BLOCK_TYPE_CURLY_BRACE === $blockType['type']) {
if (Tokens::BLOCK_TYPE_CURLY_BRACE === $blockType['type'] || !$blockType['isStart']) {
break;
}

Expand Down
25 changes: 25 additions & 0 deletions tests/Fixer/FunctionNotation/SingleLineThrowFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,30 @@ public static function provideFix80Cases(): iterable
3 => "b"
});',
];

yield [
'<?php
$var = [
$something[1] ?? throw new Exception(123)
];
',
'<?php
$var = [
$something[1] ?? throw new Exception(
123
)
];
',
];

yield [
'<?php
$var = [
$something[1] ?? throw new Exception()
];
',
];
}
}

0 comments on commit cc8d27a

Please sign in to comment.