Browse Source

fix: `TypeExpression` - handle array shape key with dash (#7841)

Kuba Werłos 1 year ago
parent
commit
4ab8fc435f

+ 1 - 1
src/DocBlock/TypeExpression.php

@@ -53,7 +53,7 @@ final class TypeExpression
                     (?<array_shape_start>(?i)(?:array|list|object)(?-i)\h*\{\h*)
                     (?<array_shape_inners>
                         (?<array_shape_inner>
-                            (?<array_shape_inner_key>(?:(?&constant)|(?&identifier))\h*\??\h*:\h*|)
+                            (?<array_shape_inner_key>(?:(?&constant)|(?&identifier)|(?&name))\h*\??\h*:\h*|)
                             (?<array_shape_inner_value>(?&types_inner))
                         )
                         (?:

+ 4 - 0
tests/DocBlock/TypeExpressionTest.php

@@ -230,6 +230,10 @@ final class TypeExpressionTest extends TestCase
         yield ['($foo🚀3 is int ? false : true)'];
 
         yield ['\'a\\\'s"\\\\\n\r\t\'|"b\\"s\'\\\\\n\r\t"', ['\'a\\\'s"\\\\\n\r\t\'', '"b\\"s\'\\\\\n\r\t"']];
+
+        yield ['array{a: int, b: int, c: int, d: int, e: int, f: int, g: int, h: int, i: int, j: int, with-dash: int}'];
+
+        yield ['array{a: int, b: int, c: int, d: int, e: int, f: int, g: int, h: int, i: int, j: int, k: int, l: int, with-dash: int}'];
     }
 
     public static function provideGetConstTypesCases(): iterable

+ 11 - 0
tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php

@@ -1528,6 +1528,17 @@ class Foo extends \A\A implements \B\A, \C\A
                 \Bar\func2(new \Bar\Service2(\Bar\CONST2));
                 EOD,
         ];
+
+        yield 'do not crash on large PHPDoc' => [<<<'PHP'
+            <?php
+            class Foo
+            {
+                /**
+                 * @return array{k0: int, k1: int, k2: int, k3: int, k4: int, k5: int, k6: int, k7: int, k8: int, k9: int, k10: int, k11: int, with-dash: int}
+                 */
+                function bar() {}
+            }
+            PHP];
     }
 
     /**