55use PHPStan \Reflection \ClassReflection ;
66use PHPStan \Reflection \MethodReflection ;
77use PHPStan \Reflection \MethodsClassReflectionExtension ;
8- use PHPStan \Type \FileTypeMapper ;
8+ use PHPStan \Type \Generic \ TemplateTypeHelper ;
99
1010class AnnotationsMethodsClassReflectionExtension implements MethodsClassReflectionExtension
1111{
1212
13- private FileTypeMapper $ fileTypeMapper ;
14-
1513 /** @var MethodReflection[][] */
1614 private array $ methods = [];
1715
18- public function __construct (FileTypeMapper $ fileTypeMapper )
19- {
20- $ this ->fileTypeMapper = $ fileTypeMapper ;
21- }
22-
2316 public function hasMethod (ClassReflection $ classReflection , string $ methodName ): bool
2417 {
25- if (!isset ($ this ->methods [$ classReflection ->getName ()])) {
26- $ this ->methods [$ classReflection ->getName ()] = $ this ->createMethods ($ classReflection , $ classReflection );
18+ if (!isset ($ this ->methods [$ classReflection ->getCacheKey ()])) {
19+ $ this ->methods [$ classReflection ->getCacheKey ()] = $ this ->createMethods ($ classReflection , $ classReflection );
2720 }
2821
29- return isset ($ this ->methods [$ classReflection ->getName ()][$ methodName ]);
22+ return isset ($ this ->methods [$ classReflection ->getCacheKey ()][$ methodName ]);
3023 }
3124
3225 public function getMethod (ClassReflection $ classReflection , string $ methodName ): MethodReflection
3326 {
34- return $ this ->methods [$ classReflection ->getName ()][$ methodName ];
27+ return $ this ->methods [$ classReflection ->getCacheKey ()][$ methodName ];
3528 }
3629
3730 /**
@@ -68,8 +61,8 @@ private function createMethods(
6861 return $ methods ;
6962 }
7063
71- $ resolvedPhpDoc = $ this -> fileTypeMapper -> getResolvedPhpDoc ( $ fileName , $ classReflection ->getName (), null , null , $ docComment );
72- foreach ($ resolvedPhpDoc -> getMethodTags () as $ methodName => $ methodTag ) {
64+ $ methodTags = $ classReflection ->getMethodTags ( );
65+ foreach ($ methodTags as $ methodName => $ methodTag ) {
7366 $ parameters = [];
7467 foreach ($ methodTag ->getParameters () as $ parameterName => $ parameterTag ) {
7568 $ parameters [] = new AnnotationsMethodParameterReflection (
@@ -85,7 +78,10 @@ private function createMethods(
8578 $ methods [$ methodName ] = new AnnotationMethodReflection (
8679 $ methodName ,
8780 $ declaringClass ,
88- $ methodTag ->getReturnType (),
81+ TemplateTypeHelper::resolveTemplateTypes (
82+ $ methodTag ->getReturnType (),
83+ $ classReflection ->getActiveTemplateTypeMap ()
84+ ),
8985 $ parameters ,
9086 $ methodTag ->isStatic (),
9187 $ this ->detectMethodVariadic ($ parameters )
0 commit comments