diff --git a/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/ArrayParser.php b/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/ArrayParser.php index 3ec70b0cd0e..27b14ec9ffa 100644 --- a/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/ArrayParser.php +++ b/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/ArrayParser.php @@ -96,6 +96,13 @@ private function resolveArrayItem(BetterTokenIterator $tokenIterator): array $tokenIterator->next(); } + $tokenIterator->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL); + + if ($tokenIterator->isCurrentTokenTypes([Lexer::TOKEN_CLOSE_CURLY_BRACKET, Lexer::TOKEN_COMMA])) { + // it's a value, not a key + return [null, $key]; + } + if ($tokenIterator->isCurrentTokenTypes( [Lexer::TOKEN_EQUAL, Lexer::TOKEN_COLON] ) || $tokenIterator->isNextTokenTypes([Lexer::TOKEN_EQUAL, Lexer::TOKEN_COLON])) { diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/nested_array_with_constants.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/nested_array_with_constants.php.inc new file mode 100644 index 00000000000..951092472f6 --- /dev/null +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/nested_array_with_constants.php.inc @@ -0,0 +1,43 @@ + +----- + ['foo' => ['bar']], 0 => ConstantReference::LAST_NAME])] +#[GenericAnnotation(some: [ConstantReference::LAST_NAME, 'trailingValue'])] +final class ArrayWithConstantAsKey +{ +} + +?> diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Source/ConstantReference.php b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Source/ConstantReference.php index e4575dd3844..becf2ffa4dd 100644 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Source/ConstantReference.php +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Source/ConstantReference.php @@ -7,4 +7,5 @@ final class ConstantReference { public const FIRST_NAME = 'firstName'; + public const LAST_NAME = 'lastName'; }