diff --git a/src/DocBlock/TypeExpression.php b/src/DocBlock/TypeExpression.php index 35e1c1a9339..a8577f3468e 100644 --- a/src/DocBlock/TypeExpression.php +++ b/src/DocBlock/TypeExpression.php @@ -108,7 +108,7 @@ final class TypeExpression (?: \h*,\h* (?&callable_argument) - )* + )*+ (?:\h*,\h*)? |) \h*\) @@ -125,7 +125,7 @@ final class TypeExpression (?: \h*,\h* (?&types_inner) - )* + )*+ (?:\h*,\h*)? ) \h*> @@ -196,13 +196,13 @@ final class TypeExpression (\h*\[\h*\])* ) (?:(?=1)0 - (? + (?(?> (?&type) (?: \h*[|&]\h* (?&type) )*+ - ) + )) |) )'; diff --git a/tests/DocBlock/TypeExpressionTest.php b/tests/DocBlock/TypeExpressionTest.php index e966529dd7b..99ca1140b42 100644 --- a/tests/DocBlock/TypeExpressionTest.php +++ b/tests/DocBlock/TypeExpressionTest.php @@ -165,6 +165,8 @@ public static function provideGetTypesCases(): iterable yield ['OBJECT { x: 1 }']; + yield ['array{a: int, b: int, with-dash: int}']; + yield ['callable']; yield ['callable(string)']; @@ -249,11 +251,11 @@ public static function provideGetTypesCases(): iterable 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 ['string'.str_repeat('[]', 128)]; - 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}']; + yield [str_repeat('array<', 128).'string'.str_repeat('>', 128)]; - yield [self::createHugeArrayShapeType()]; + yield [self::makeLongArrayShapeType()]; } public static function provideGetConstTypesCases(): iterable @@ -401,7 +403,7 @@ public static function provideParseInvalidExceptionCases(): iterable yield 'generic Closure with non-identifier template argument' => ['Closure(): void']; - yield [substr(self::createHugeArrayShapeType(), 0, -1)]; + yield [substr(self::makeLongArrayShapeType(), 0, -1)]; } public function testHugeType(): void @@ -923,18 +925,15 @@ public static function provideSortTypesCases(): iterable ]; } - private static function createHugeArrayShapeType(): string + private static function makeLongArrayShapeType(): string { - return sprintf( - 'array{%s}', - implode( - ', ', - array_map( - static fn (int $k): string => sprintf('key%sno%d: int', 0 === $k % 2 ? '-' : '_', $k), - range(1, 1_000), - ), + return 'array{'.implode( + ', ', + array_map( + static fn (int $k): string => sprintf('key%sno%d: int', 0 === $k % 2 ? '-' : '_', $k), + range(1, 1_000), ), - ); + ).'}'; } /** diff --git a/tests/Fixer/Phpdoc/PhpdocArrayTypeFixerTest.php b/tests/Fixer/Phpdoc/PhpdocArrayTypeFixerTest.php index cd77d047fbd..b8139d5e98c 100644 --- a/tests/Fixer/Phpdoc/PhpdocArrayTypeFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocArrayTypeFixerTest.php @@ -145,5 +145,16 @@ public static function provideFixCases(): iterable ' */', ''; + $input .= '[]'; + } + + yield [ + sprintf('