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

Issue:
With namespace {}, "use function" is badly indented
## Bug report


### Description

`use function XXX` does not work well when in a `namespace {}`.

### Runtime version

```
…ev/github.com/jolicode/docker-starter(feat/castor *+) php-cs-fixer -V
PHP CS Fixer 3.17.0 Brazilian Kangaroo by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.2.6
```

### Used command

```
…ev/github.com/jolicode/docker-starter(feat/castor *+) php-cs-fixer -V
PHP CS Fixer 3.17.0 Brazilian Kangaroo by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.2.6
```

### Configuration file

```php
$finder = PhpCsFixer\Finder::create()
    ->ignoreVCSIgnored(true)
    ->ignoreDotFiles(false)
    ->in(__DIR__)
    ->append([
        __FILE__,
    ])
;

return (new PhpCsFixer\Config())
    ->setRiskyAllowed(true)
    ->setRules([
        '@PhpCsFixer' => true,
    ])
    ->setFinder($finder)
;
```
### Code snippet that reproduces the problem

```php
<?php

namespace
{
    use c\MyClass;
    use function f\my_function;

    $m = new MyClass();
    my_function();

}

namespace c
{

    class MyClass
    {
    }
}

namespace f
{
    function my_function()
    {
        echo 'Hello world!';
    }

}
```

⬇ is transformed in ⬇ 

```php
<?php

namespace {
    use c\MyClass;

use function f\my_function;

    $m = new MyClass();
    my_function();
}

namespace c
{
    class MyClass
    {
    }
}

namespace f
{
    function my_function()
    {
        echo 'Hello world!';
    }
}
```


Discussion:
It's technically a feature request as there is a test to ensure the indent will be changed that way: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.20.0/tests/Fixer/Whitespace/BlankLineBetweenImportGroupsFixerTest.php#L426-L459



Patch:
diff --git a/src/Fixer/Whitespace/BlankLineBetweenImportGroupsFixer.php b/src/Fixer/Whitespace/BlankLineBetweenImportGroupsFixer.php
index b67de37c667..1976aefb3a1 100644
--- a/src/Fixer/Whitespace/BlankLineBetweenImportGroupsFixer.php
+++ b/src/Fixer/Whitespace/BlankLineBetweenImportGroupsFixer.php
@@ -19,8 +19,8 @@
 use PhpCsFixer\FixerDefinition\CodeSample;
 use PhpCsFixer\FixerDefinition\FixerDefinition;
 use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
+use PhpCsFixer\Tokenizer\Analyzer\WhitespacesAnalyzer;
 use PhpCsFixer\Tokenizer\CT;
-use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
 use PhpCsFixer\Tokenizer\TokensAnalyzer;
 
@@ -154,12 +154,9 @@ private function ensureLine(Tokens $tokens, int $index): void
         }
 
         $index = $this->getInsertIndex($tokens, $index);
+        $indent = WhitespacesAnalyzer::detectIndent($tokens, $index);
 
-        if ($tokens[$index]->isWhitespace()) {
-            $tokens[$index] = new Token([T_WHITESPACE, $lineEnding]);
-        } else {
-            $tokens->insertSlices([$index + 1 => [new Token([T_WHITESPACE, $lineEnding])]]);
-        }
+        $tokens->ensureWhitespaceAtIndex($index, 1, $lineEnding.$indent);
     }
 
     private function getInsertIndex(Tokens $tokens, int $index): int


Test patch:
diff --git a/tests/Fixer/Whitespace/BlankLineBetweenImportGroupsFixerTest.php b/tests/Fixer/Whitespace/BlankLineBetweenImportGroupsFixerTest.php
index 594239618c7..d798c4ac540 100644
--- a/tests/Fixer/Whitespace/BlankLineBetweenImportGroupsFixerTest.php
+++ b/tests/Fixer/Whitespace/BlankLineBetweenImportGroupsFixerTest.php
@@ -428,23 +428,23 @@ public static function provideFixTypesOrderAndNewlinesCases(): iterable
 namespace A\B6 {
     use C1\B1;
 
-use const C6\Z1;
+    use const C6\Z1;
 
-use C2\B2;
+    use C2\B2;
 
-use const C7\Z2;
+    use const C7\Z2;
 
-use C3\B3;
+    use C3\B3;
 
-use const C8\Z3;
+    use const C8\Z3;
 
-use C4\B4;
+    use C4\B4;
 
-use const C9\Z4;
+    use const C9\Z4;
 
-use C5\B5;
+    use C5\B5;
 
-use const C0\Z5;
+    use const C0\Z5;
 }
             ',
             '<?php
@@ -463,27 +463,27 @@ public static function provideFixTypesOrderAndNewlinesCases(): iterable
 namespace A\B1 {
     use C\B;
 
-use const C\Z;
+    use const C\Z;
 }
 namespace A\B2 {
     use C\B;
 
-use const C\Z;
+    use const C\Z;
 }
 namespace A\B3 {
     use C\B;
 
-use const C\Z;
+    use const C\Z;
 }
 namespace A\B4 {
     use C\B;
 
-use const C\Z;
+    use const C\Z;
 }
 namespace A\B5 {
     use C\B;
 
-use const C\Z;
+    use const C\Z;
 }
             ',
             '<?php