Skip to content

Commit

Permalink
bug: Fix indentation after control structure in switch (#6473)
Browse files Browse the repository at this point in the history
Fix indentation after control structure in switch
  • Loading branch information
julienfalque authored Jul 11, 2022
1 parent f0c46ff commit 3b5d696
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Fixer/Whitespace/StatementIndentationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ private function findCaseBlockEnd(Tokens $tokens, int $index): int
continue;
}

if ($tokens[$index]->equals('{')) {
$index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);

continue;
}

if ($tokens[$index]->equalsAny([[T_CASE], [T_DEFAULT]])) {
return $index;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Fixer/Whitespace/StatementIndentationFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,25 @@ public function foo(
"foo" => $foo,
"bar" => $bar,
]) {
}',
];

yield 'switch case with control structure' => [
'<?php
switch ($foo) {
case true:
if ($bar) {
bar();
}
return true;
}',
'<?php
switch ($foo) {
case true:
if ($bar) {
bar();
}
return true;
}',
];
}
Expand Down

0 comments on commit 3b5d696

Please sign in to comment.