33namespace PHPStan \Analyser ;
44
55use PhpParser \Node \Name ;
6+ use PHPStan \DependencyInjection \Container ;
7+ use PHPStan \PhpDoc \TypeStringResolver ;
68use PHPStan \Reflection \NamespaceAnswerer ;
79use PHPStan \Reflection \ReflectionProvider ;
810use PHPStan \Reflection \ReflectionProvider \ReflectionProviderProvider ;
@@ -34,7 +36,7 @@ final class ConstantResolver
3436 /**
3537 * @param string[] $dynamicConstantNames
3638 */
37- public function __construct (private ReflectionProviderProvider $ reflectionProviderProvider , private array $ dynamicConstantNames )
39+ public function __construct (private ReflectionProviderProvider $ reflectionProviderProvider , private array $ dynamicConstantNames, private ? Container $ container )
3840 {
3941 }
4042
@@ -305,7 +307,10 @@ public function resolveConstantType(string $constantName, Type $constantType): T
305307 if ($ constantType ->isConstantValue ()->yes ()) {
306308 if (array_key_exists ($ constantName , $ this ->dynamicConstantNames )) {
307309 $ phpdocTypes = $ this ->dynamicConstantNames [$ constantName ];
308- return $ this ->reflectionProviderProvider ->getReflectionProvider ()->getSignatureMapProvider ()->getTypeFromString ($ phpdocTypes , null );
310+ $ typeStringResolver = $ this ->container ?->getByType(TypeStringResolver::class);
311+ if ($ typeStringResolver !== null ) {
312+ return $ typeStringResolver ->resolve ($ phpdocTypes , new NameScope (null , [], null ));
313+ }
309314 }
310315 if (in_array ($ constantName , $ this ->dynamicConstantNames , true )) {
311316 return $ constantType ->generalize (GeneralizePrecision::lessSpecific ());
@@ -325,7 +330,10 @@ public function resolveClassConstantType(string $className, string $constantName
325330
326331 if ($ constantType ->isConstantValue ()->yes ()) {
327332 $ phpdocTypes = $ this ->dynamicConstantNames [$ lookupConstantName ];
328- return $ this ->getReflectionProvider ()->getSignatureMapProvider ()->getTypeFromString ($ phpdocTypes , $ className );
333+ $ typeStringResolver = $ this ->container ?->getByType(TypeStringResolver::class);
334+ if ($ typeStringResolver !== null ) {
335+ return $ typeStringResolver ->resolve ($ phpdocTypes , new NameScope (null , [], $ className ));
336+ }
329337 }
330338 }
331339
0 commit comments