@@ -302,8 +302,14 @@ public function resolvePredefinedConstant(string $resolvedConstantName): ?Type
302302
303303 public function resolveConstantType (string $ constantName , Type $ constantType ): Type
304304 {
305- if ($ constantType ->isConstantValue ()->yes () && in_array ($ constantName , $ this ->dynamicConstantNames , true )) {
306- return $ constantType ->generalize (GeneralizePrecision::lessSpecific ());
305+ if ($ constantType ->isConstantValue ()->yes ()) {
306+ if (array_key_exists ($ constantName , $ this ->dynamicConstantNames )) {
307+ $ phpdocTypes = $ this ->dynamicConstantNames [$ constantName ];
308+ return $ this ->reflectionProviderProvider ->getReflectionProvider ()->getSignatureMapProvider ()->getTypeFromString ($ phpdocTypes , null );
309+ }
310+ if (in_array ($ constantName , $ this ->dynamicConstantNames , true )) {
311+ return $ constantType ->generalize (GeneralizePrecision::lessSpecific ());
312+ }
307313 }
308314
309315 return $ constantType ;
@@ -312,6 +318,17 @@ public function resolveConstantType(string $constantName, Type $constantType): T
312318 public function resolveClassConstantType (string $ className , string $ constantName , Type $ constantType , ?Type $ nativeType ): Type
313319 {
314320 $ lookupConstantName = sprintf ('%s::%s ' , $ className , $ constantName );
321+ if (array_key_exists ($ lookupConstantName , $ this ->dynamicConstantNames )) {
322+ if ($ nativeType !== null ) {
323+ return $ nativeType ;
324+ }
325+
326+ if ($ constantType ->isConstantValue ()->yes ()) {
327+ $ phpdocTypes = $ this ->dynamicConstantNames [$ lookupConstantName ];
328+ return $ this ->getReflectionProvider ()->getSignatureMapProvider ()->getTypeFromString ($ phpdocTypes , $ className );
329+ }
330+ }
331+
315332 if (in_array ($ lookupConstantName , $ this ->dynamicConstantNames , true )) {
316333 if ($ nativeType !== null ) {
317334 return $ nativeType ;
0 commit comments