2121use PHPStan \PhpDocParser \Parser \TypeParser ;
2222use PHPStan \PhpDocParser \ParserConfig ;
2323use Rector \BetterPhpDocParser \Contract \PhpDocParser \PhpDocNodeDecoratorInterface ;
24+ use Rector \BetterPhpDocParser \NodeDecorator \ArrayItemClassNameDecorator ;
25+ use Rector \BetterPhpDocParser \NodeDecorator \ConstExprClassNameDecorator ;
26+ use Rector \BetterPhpDocParser \NodeDecorator \DoctrineAnnotationDecorator ;
27+ use Rector \BetterPhpDocParser \NodeDecorator \PhpDocTagGenericUsesDecorator ;
2428use Rector \BetterPhpDocParser \PhpDocInfo \TokenIteratorFactory ;
2529use Rector \BetterPhpDocParser \ValueObject \Parser \BetterTokenIterator ;
2630use Rector \BetterPhpDocParser \ValueObject \PhpDocAttributeKey ;
@@ -44,16 +48,32 @@ final class BetterPhpDocParser extends PhpDocParser
4448 private const string MULTI_NEW_LINES_REGEX = '#(?<new_line>\r\n|\n){2,}# ' ;
4549
4650 /**
47- * @param PhpDocNodeDecoratorInterface[] $phpDocNodeDecorators
51+ * @var PhpDocNodeDecoratorInterface[]
4852 */
53+ private readonly array $ phpDocNodeDecorators ;
54+
4955 public function __construct (
5056 ParserConfig $ parserConfig ,
5157 TypeParser $ typeParser ,
5258 ConstExprParser $ constExprParser ,
5359 private readonly TokenIteratorFactory $ tokenIteratorFactory ,
54- private readonly array $ phpDocNodeDecorators ,
60+ ConstExprClassNameDecorator $ constExprClassNameDecorator ,
61+ DoctrineAnnotationDecorator $ doctrineAnnotationDecorator ,
62+ ArrayItemClassNameDecorator $ arrayItemClassNameDecorator ,
63+ PhpDocTagGenericUsesDecorator $ phpDocTagGenericUsesDecorator ,
5564 private readonly PrivatesAccessor $ privatesAccessor ,
5665 ) {
66+ // The decorator order below is significant; keep it as is. DoctrineAnnotationDecorator must
67+ // run before ArrayItemClassNameDecorator, which resolves class names inside the array items the
68+ // former produces. A wrong order silently drops annotation class usages and strips their imports.
69+ // They are injected explicitly, not autodiscovered, so the order stays under our control.
70+ $ this ->phpDocNodeDecorators = [
71+ $ constExprClassNameDecorator ,
72+ $ doctrineAnnotationDecorator ,
73+ $ arrayItemClassNameDecorator ,
74+ $ phpDocTagGenericUsesDecorator ,
75+ ];
76+
5777 parent ::__construct (
5878 // ParserConfig
5979 $ parserConfig ,
0 commit comments