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

Issue:
Support for casing of types in arrow functions
## Feature request

As it was discussed in #6623 ([here](https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/6623#discussion_r965609048)), there is no support for type casing in arrow functions:

```diff
- array_filter([], fn (NULL $A): NULL => $A);
+ array_filter([], fn (null $A): null => $A);
```

I don't know if it's only for new PHP 8.2 types (`null`, `true`, `false`) or for all, but it should be fixed anyway.


Discussion:
The `NativeFunctionTypeDeclarationCasingFixer` looks for `T_FUNCTION` (i.e. `function`) as such for an any PHP version it does not handle `T_FN` (i.e. `fn`).
(for ref.: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.11.0/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php#L119)

@Wirone , wanna implement this?



Patch:
diff --git a/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php b/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php
index 8ba6c187fe7..6ed3f08d2ba 100644
--- a/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php
+++ b/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php
@@ -118,7 +118,7 @@ public function getDefinition(): FixerDefinitionInterface
      */
     public function isCandidate(Tokens $tokens): bool
     {
-        return $tokens->isTokenKindFound(T_FUNCTION);
+        return $tokens->isAnyTokenKindsFound([T_FUNCTION, T_FN]);
     }
 
     /**
@@ -127,7 +127,7 @@ public function isCandidate(Tokens $tokens): bool
     protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
     {
         for ($index = $tokens->count() - 1; $index >= 0; --$index) {
-            if ($tokens[$index]->isGivenKind(T_FUNCTION)) {
+            if ($tokens[$index]->isGivenKind([T_FUNCTION, T_FN])) {
                 $this->fixFunctionReturnType($tokens, $index);
                 $this->fixFunctionArgumentTypes($tokens, $index);
             }


Test patch:
diff --git a/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php b/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php
index c7ba7f8ef94..6b2ac03ba50 100644
--- a/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php
+++ b/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php
@@ -132,6 +132,10 @@ function Foo(INTEGER $a) {}
                 '<?php return function (callable $c) {};',
                 '<?php return function (CALLABLE $c) {};',
             ],
+            [
+                '<?php return fn (callable $c): int => 1;',
+                '<?php return fn (CALLABLE $c): INT => 1;',
+            ],
         ];
     }
 
@@ -162,6 +166,11 @@ public static function provideFix80Cases(): iterable
             '<?php class T { public function Foo(Mixed $A): MIXED {}}',
         ];
 
+        yield 'mixed in arrow function' => [
+            '<?php return fn (mixed $c): mixed => 1;',
+            '<?php return fn (MiXeD $c): MIXED => 1;',
+        ];
+
         yield [
             '<?php function foo(int|bool $x) {}',
             '<?php function foo(INT|BOOL $x) {}',
@@ -186,6 +195,11 @@ public static function provideFix80Cases(): iterable
             '<?php function foo(): string|null {}',
             '<?php function foo(): string|NULL {}',
         ];
+
+        yield 'union types in arrow function' => [
+            '<?php return fn (string|null $c): int|null => 1;',
+            '<?php return fn (string|NULL $c): INT|NULL => 1;',
+        ];
     }
 
     /**
@@ -218,6 +232,11 @@ public function testFix82(string $expected, string $input): void
 
     public static function provideFix82Cases(): iterable
     {
+        yield 'disjunctive normal form types in arrow function' => [
+            '<?php return fn ((A&B)|C|null $c): (X&Y)|Z|null => 1;',
+            '<?php return fn ((A&B)|C|Null $c): (X&Y)|Z|NULL => 1;',
+        ];
+
         foreach (['true', 'false', 'null'] as $type) {
             yield sprintf('standalone type `%s` in class method', $type) => [
                 sprintf('<?php class T { public function Foo(%s $A): %1$s {return $A;}}', $type),
@@ -233,6 +252,11 @@ public static function provideFix82Cases(): iterable
                 sprintf('<?php array_filter([], function (%s $A): %1$s {return $A;});', $type),
                 sprintf('<?php array_filter([], function (%s $A): %1$s {return $A;});', strtoupper($type)),
             ];
+
+            yield sprintf('standalone type `%s` in arrow function', $type) => [
+                sprintf('<?php array_filter([], fn (%s $A): %1$s => $A);', $type),
+                sprintf('<?php array_filter([], fn (%s $A): %1$s => $A);', strtoupper($type)),
+            ];
         }
     }
 }