@@ -27,6 +27,9 @@ class StubPhpDocProvider
2727 /** @var array<string, array<string, ResolvedPhpDocBlock|null>> */
2828 private array $ propertyMap = [];
2929
30+ /** @var array<string, array<string, ResolvedPhpDocBlock|null>> */
31+ private array $ constantMap = [];
32+
3033 /** @var array<string, array<string, null>> */
3134 private array $ methodMap = [];
3235
@@ -46,6 +49,9 @@ class StubPhpDocProvider
4649 /** @var array<string, array<string, array{string, string}>> */
4750 private array $ knownPropertiesDocComments = [];
4851
52+ /** @var array<string, array<string, array{string, string}>> */
53+ private array $ knownConstantsDocComments = [];
54+
4955 /** @var array<string, array<string, array{string, string}>> */
5056 private array $ knownMethodsDocComments = [];
5157
@@ -122,6 +128,32 @@ public function findPropertyPhpDoc(string $className, string $propertyName): ?Re
122128 return null ;
123129 }
124130
131+ public function findClassConstantPhpDoc (string $ className , string $ constantName ): ?ResolvedPhpDocBlock
132+ {
133+ if (!$ this ->isKnownClass ($ className )) {
134+ return null ;
135+ }
136+
137+ if (array_key_exists ($ constantName , $ this ->constantMap [$ className ])) {
138+ return $ this ->constantMap [$ className ][$ constantName ];
139+ }
140+
141+ if (array_key_exists ($ constantName , $ this ->knownConstantsDocComments [$ className ])) {
142+ [$ file , $ docComment ] = $ this ->knownConstantsDocComments [$ className ][$ constantName ];
143+ $ this ->constantMap [$ className ][$ constantName ] = $ this ->fileTypeMapper ->getResolvedPhpDoc (
144+ $ file ,
145+ $ className ,
146+ null ,
147+ null ,
148+ $ docComment
149+ );
150+
151+ return $ this ->constantMap [$ className ][$ constantName ];
152+ }
153+
154+ return null ;
155+ }
156+
125157 /**
126158 * @param string $className
127159 * @param string $methodName
@@ -306,7 +338,9 @@ private function initializeKnownElementNode(string $stubFile, Node $node): void
306338
307339 $ this ->methodMap [$ className ] = [];
308340 $ this ->propertyMap [$ className ] = [];
341+ $ this ->constantMap [$ className ] = [];
309342 $ this ->knownPropertiesDocComments [$ className ] = [];
343+ $ this ->knownConstantsDocComments [$ className ] = [];
310344 $ this ->knownMethodsDocComments [$ className ] = [];
311345
312346 foreach ($ node ->stmts as $ stmt ) {
@@ -319,6 +353,14 @@ private function initializeKnownElementNode(string $stubFile, Node $node): void
319353 }
320354 $ this ->knownPropertiesDocComments [$ className ][$ property ->name ->toString ()] = [$ stubFile , $ docComment ->getText ()];
321355 }
356+ } elseif ($ stmt instanceof Node \Stmt \ClassConst) {
357+ foreach ($ stmt ->consts as $ const ) {
358+ if ($ docComment === null ) {
359+ $ this ->constantMap [$ className ][$ const ->name ->toString ()] = null ;
360+ continue ;
361+ }
362+ $ this ->knownConstantsDocComments [$ className ][$ const ->name ->toString ()] = [$ stubFile , $ docComment ->getText ()];
363+ }
322364 } elseif ($ stmt instanceof Node \Stmt \ClassMethod) {
323365 if ($ docComment === null ) {
324366 $ this ->methodMap [$ className ][$ stmt ->name ->toString ()] = null ;
0 commit comments