Browse Source

fix: `NullableTypeDeclarationFixer` - insert correct token (#8118)

Kuba Werłos 7 months ago
parent
commit
8be8d7a1e0

+ 6 - 6
src/Fixer/LanguageConstruct/NullableTypeDeclarationFixer.php

@@ -307,18 +307,18 @@ class ValueObject
     private function createTypeDeclarationTokens(array $types, bool $isQuestionMarkSyntax): array
     {
         static $specialTypes = [
-            '?' => [CT::T_NULLABLE_TYPE, '?'],
-            'array' => [CT::T_ARRAY_TYPEHINT, 'array'],
-            'callable' => [T_CALLABLE, 'callable'],
-            'static' => [T_STATIC, 'static'],
+            '?' => CT::T_NULLABLE_TYPE,
+            'array' => CT::T_ARRAY_TYPEHINT,
+            'callable' => T_CALLABLE,
+            'static' => T_STATIC,
         ];
 
         $count = \count($types);
         $newTokens = [];
 
         foreach ($types as $index => $type) {
-            if (isset($specialTypes[$type])) {
-                $newTokens[] = new Token($specialTypes[$type]);
+            if (isset($specialTypes[strtolower($type)])) {
+                $newTokens[] = new Token([$specialTypes[strtolower($type)], $type]);
             } else {
                 foreach (explode('\\', $type) as $nsIndex => $value) {
                     if (0 === $nsIndex && '' === $value) {

+ 2 - 2
tests/Fixer/LanguageConstruct/NullableTypeDeclarationFixerTest.php

@@ -280,14 +280,14 @@ class Infinite
 class Foo
 {
     public function bar(null|array $config = null): null {}
-    public function baz(null|array $config = NULL): NULL {}
+    public function baz(null|ARRAY $config = NULL): NULL {}
 }
 ',
             '<?php
 class Foo
 {
     public function bar(?array $config = null): null {}
-    public function baz(?array $config = NULL): NULL {}
+    public function baz(?ARRAY $config = NULL): NULL {}
 }
 ',
             ['syntax' => 'union'],