Repository: FriendsOfPHP/PHP-CS-Fixer (php)

Issue:
Braces rule: Omitting "break" in switch incorrectly indents closing brace
## Bug report

Adding another test case for incorrect indentation, adding to #6470.

PHP CS Fixer 3.9.5 Grand Awaiting by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 7.4.30

Command:
php-cs-fixer fix -vvv --rules=braces testcase.php

### Code snippet that reproduces the problem

This code snippet should not be changed:

```php
<?php

function foo($var)
{
    switch ($var) {
        case 'one':
            break;
        case 'two':
            break;
        default:
    }
}

switch ($var) {
    case 'one':
        break;
    case 'two':
        break;
    default:
}
```

Version 3.9.5 is indenting the closing brace of the switch statement one level too far.

Pull request description:
bug: Fix indentation for switch ending with empty case
Fixes #6523.

Patch:
diff --git a/src/Fixer/Whitespace/StatementIndentationFixer.php b/src/Fixer/Whitespace/StatementIndentationFixer.php
index 4cc8fc7e6..34ca8f984 100644
--- a/src/Fixer/Whitespace/StatementIndentationFixer.php
+++ b/src/Fixer/Whitespace/StatementIndentationFixer.php
@@ -124,6 +124,17 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
             0,
             $this->extractIndent($this->computeNewLineContent($tokens, 0)),
         );
+
+        /**
+         * @var list<array{
+         *     type: 'block'|'block_signature'|'statement',
+         *     skip: bool,
+         *     end_index: int,
+         *     end_index_inclusive: bool,
+         *     initial_indent: string,
+         *     is_indented_block: bool,
+         * }> $scopes
+         */
         $scopes = [
             [
                 'type' => 'block',
@@ -198,6 +209,13 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
                     'initial_indent' => $initialIndent,
                     'is_indented_block' => true,
                 ];
+                ++$currentScope;
+
+                while ($index >= $scopes[$currentScope]['end_index']) {
+                    array_pop($scopes);
+
+                    --$currentScope;
+                }
 
                 continue;
             }


Test patch:
diff --git a/tests/Fixer/Whitespace/StatementIndentationFixerTest.php b/tests/Fixer/Whitespace/StatementIndentationFixerTest.php
index f794935c6..e7f204718 100644
--- a/tests/Fixer/Whitespace/StatementIndentationFixerTest.php
+++ b/tests/Fixer/Whitespace/StatementIndentationFixerTest.php
@@ -760,6 +760,20 @@ public function foo() {
         break;
     default:
         // Nothing to do
+}',
+        ];
+
+        yield 'switch ending with empty case' => [
+            '<?php
+switch ($foo) {
+    case 1:
+}',
+        ];
+
+        yield 'switch ending with empty default' => [
+            '<?php
+switch ($foo) {
+    default:
 }',
         ];
     }