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

Issue:
Multiline braces issue with static return type
## Bug report

With a `static` return type the brace is moved to the next line, even though that doesn't happen with other return types. 3.8.0 does not exhibit this issue, all newer versions do.

```
vendor/bin/php-cs-fixer -V
PHP CS Fixer 3.9.3 Grand Awaiting by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.0.20
```

### Code snippet that reproduces the problem

```php
<?php
class Foo
{
    public function doSomething(
    ): static {
        return $this;
    }

    public function doSomethingElse(
    ): self {
        return $this;
    }
}
```

This gets (unexpectedly) changed to:

```php
<?php
class Foo
{
    public function doSomething(
    ): static
    {
        return $this;
    }

    public function doSomethingElse(
    ): self {
        return $this;
    }
}
```


Discussion:

Patch:
diff --git a/src/Fixer/Basic/CurlyBracesPositionFixer.php b/src/Fixer/Basic/CurlyBracesPositionFixer.php
index d2b7f7beb44..a3a469b5912 100644
--- a/src/Fixer/Basic/CurlyBracesPositionFixer.php
+++ b/src/Fixer/Basic/CurlyBracesPositionFixer.php
@@ -255,7 +255,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
                 $previousTokenIndex = $openBraceIndex;
                 do {
                     $previousTokenIndex = $tokens->getPrevMeaningfulToken($previousTokenIndex);
-                } while ($tokens[$previousTokenIndex]->isGivenKind([CT::T_TYPE_COLON, CT::T_NULLABLE_TYPE, T_STRING, T_NS_SEPARATOR, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION, CT::T_TYPE_INTERSECTION]));
+                } while ($tokens[$previousTokenIndex]->isGivenKind([CT::T_TYPE_COLON, CT::T_NULLABLE_TYPE, T_STRING, T_NS_SEPARATOR, CT::T_ARRAY_TYPEHINT, T_STATIC, CT::T_TYPE_ALTERNATION, CT::T_TYPE_INTERSECTION]));
 
                 if ($tokens[$previousTokenIndex]->equals(')')) {
                     if ($tokens[--$previousTokenIndex]->isComment()) {


Test patch:
diff --git a/tests/Fixer/Basic/CurlyBracesPositionFixerTest.php b/tests/Fixer/Basic/CurlyBracesPositionFixerTest.php
index 4f3b6f50249..89623557a12 100644
--- a/tests/Fixer/Basic/CurlyBracesPositionFixerTest.php
+++ b/tests/Fixer/Basic/CurlyBracesPositionFixerTest.php
@@ -664,6 +664,13 @@ function sum(
                     int|float $second,
                 ): int|float {
                 }',
+            '<?php
+                function sum(
+                    int|float $first,
+                    int|float $second,
+                ): int|float
+                {
+                }',
         ];
 
         yield 'function (multiline + union return with whitespace)' => [
@@ -673,6 +680,33 @@ function sum(
                     int|float $second,
                 ): int | float {
                 }',
+            '<?php
+                function sum(
+                    int|float $first,
+                    int|float $second,
+                ): int | float
+                {
+                }',
+        ];
+
+        yield 'method with static return type' => [
+            '<?php
+                class Foo
+                {
+                    function sum(
+                        $foo
+                    ): static {
+                    }
+                }',
+            '<?php
+                class Foo
+                {
+                    function sum(
+                        $foo
+                    ): static
+                    {
+                    }
+                }',
         ];
     }