@@ -45,7 +45,7 @@ final class PhpStanExtractor implements PropertyTypeExtractorInterface, Construc
45
45
/** @var NameScopeFactory */
46
46
private $ nameScopeFactory ;
47
47
48
- /** @var array<string, array{PhpDocNode|null, int|null, string|null}> */
48
+ /** @var array<string, array{PhpDocNode|null, int|null, string|null, string|null }> */
49
49
private $ docBlocks = [];
50
50
private $ phpStanTypeHelper ;
51
51
private $ mutatorPrefixes ;
@@ -72,8 +72,8 @@ public function __construct(array $mutatorPrefixes = null, array $accessorPrefix
72
72
public function getTypes (string $ class , string $ property , array $ context = []): ?array
73
73
{
74
74
/** @var PhpDocNode|null $docNode */
75
- [$ docNode , $ source , $ prefix ] = $ this ->getDocBlock ($ class , $ property );
76
- $ nameScope = $ this ->nameScopeFactory ->create ($ class );
75
+ [$ docNode , $ source , $ prefix, $ declaringClass ] = $ this ->getDocBlock ($ class , $ property );
76
+ $ nameScope = $ this ->nameScopeFactory ->create ($ class, $ declaringClass );
77
77
if (null === $ docNode ) {
78
78
return null ;
79
79
}
@@ -184,7 +184,7 @@ private function filterDocBlockParams(PhpDocNode $docNode, string $allowedParam)
184
184
}
185
185
186
186
/**
187
- * @return array{PhpDocNode|null, int|null, string|null}
187
+ * @return array{PhpDocNode|null, int|null, string|null, string|null }
188
188
*/
189
189
private function getDocBlock (string $ class , string $ property ): array
190
190
{
@@ -196,20 +196,23 @@ private function getDocBlock(string $class, string $property): array
196
196
197
197
$ ucFirstProperty = ucfirst ($ property );
198
198
199
- if ($ docBlock = $ this ->getDocBlockFromProperty ($ class , $ property )) {
200
- $ data = [$ docBlock , self ::PROPERTY , null ];
201
- } elseif ([$ docBlock ] = $ this ->getDocBlockFromMethod ($ class , $ ucFirstProperty , self ::ACCESSOR )) {
202
- $ data = [$ docBlock , self ::ACCESSOR , null ];
203
- } elseif ([$ docBlock , $ prefix ] = $ this ->getDocBlockFromMethod ($ class , $ ucFirstProperty , self ::MUTATOR )) {
204
- $ data = [$ docBlock , self ::MUTATOR , $ prefix ];
199
+ if ([ $ docBlock, $ declaringClass ] = $ this ->getDocBlockFromProperty ($ class , $ property )) {
200
+ $ data = [$ docBlock , self ::PROPERTY , null , $ declaringClass ];
201
+ } elseif ([$ docBlock, $ _ , $ declaringClass ] = $ this ->getDocBlockFromMethod ($ class , $ ucFirstProperty , self ::ACCESSOR )) {
202
+ $ data = [$ docBlock , self ::ACCESSOR , null , $ declaringClass ];
203
+ } elseif ([$ docBlock , $ prefix, $ declaringClass ] = $ this ->getDocBlockFromMethod ($ class , $ ucFirstProperty , self ::MUTATOR )) {
204
+ $ data = [$ docBlock , self ::MUTATOR , $ prefix, $ declaringClass ];
205
205
} else {
206
- $ data = [null , null , null ];
206
+ $ data = [null , null , null , null ];
207
207
}
208
208
209
209
return $ this ->docBlocks [$ propertyHash ] = $ data ;
210
210
}
211
211
212
- private function getDocBlockFromProperty (string $ class , string $ property ): ?PhpDocNode
212
+ /**
213
+ * @return array{PhpDocNode, string}|null
214
+ */
215
+ private function getDocBlockFromProperty (string $ class , string $ property ): ?array
213
216
{
214
217
// Use a ReflectionProperty instead of $class to get the parent class if applicable
215
218
try {
@@ -226,11 +229,11 @@ private function getDocBlockFromProperty(string $class, string $property): ?PhpD
226
229
$ phpDocNode = $ this ->phpDocParser ->parse ($ tokens );
227
230
$ tokens ->consumeTokenType (Lexer::TOKEN_END );
228
231
229
- return $ phpDocNode ;
232
+ return [ $ phpDocNode, $ reflectionProperty -> class ] ;
230
233
}
231
234
232
235
/**
233
- * @return array{PhpDocNode, string}|null
236
+ * @return array{PhpDocNode, string, string }|null
234
237
*/
235
238
private function getDocBlockFromMethod (string $ class , string $ ucFirstProperty , int $ type ): ?array
236
239
{
@@ -269,6 +272,6 @@ private function getDocBlockFromMethod(string $class, string $ucFirstProperty, i
269
272
$ phpDocNode = $ this ->phpDocParser ->parse ($ tokens );
270
273
$ tokens ->consumeTokenType (Lexer::TOKEN_END );
271
274
272
- return [$ phpDocNode , $ prefix ];
275
+ return [$ phpDocNode , $ prefix, $ reflectionMethod -> class ];
273
276
}
274
277
}
0 commit comments