@@ -432,12 +432,13 @@ private function createMethod(
432
432
$ stubPhpDocParameterTypes = [];
433
433
$ stubPhpDocParameterVariadicity = [];
434
434
if (count ($ variantNames ) === 1 ) {
435
- $ stubPhpDoc = $ this ->findMethodPhpDocIncludingAncestors ($ declaringClassName , $ methodReflection ->getName (), array_map (static function (ParameterSignature $ parameterSignature ): string {
435
+ $ stubPhpDocPair = $ this ->findMethodPhpDocIncludingAncestors ($ declaringClass , $ methodReflection ->getName (), array_map (static function (ParameterSignature $ parameterSignature ): string {
436
436
return $ parameterSignature ->getName ();
437
437
}, $ methodSignature ->getParameters ()));
438
- if ($ stubPhpDoc !== null ) {
438
+ if ($ stubPhpDocPair !== null ) {
439
+ [$ stubPhpDoc , $ stubDeclaringClass ] = $ stubPhpDocPair ;
439
440
$ stubPhpDocString = $ stubPhpDoc ->getPhpDocString ();
440
- $ templateTypeMap = $ declaringClass ->getActiveTemplateTypeMap ();
441
+ $ templateTypeMap = $ stubDeclaringClass ->getActiveTemplateTypeMap ();
441
442
$ returnTag = $ stubPhpDoc ->getReturnTag ();
442
443
if ($ returnTag !== null ) {
443
444
$ stubPhpDocReturnType = $ returnTag ->getType ();
@@ -491,9 +492,14 @@ private function createMethod(
491
492
}
492
493
493
494
$ declaringTraitName = $ this ->findMethodTrait ($ methodReflection );
494
- $ resolvedPhpDoc = $ this ->findMethodPhpDocIncludingAncestors ($ declaringClassName , $ methodReflection ->getName (), array_map (static function (\ReflectionParameter $ parameter ): string {
495
+ $ resolvedPhpDoc = null ;
496
+ $ stubPhpDocPair = $ this ->findMethodPhpDocIncludingAncestors ($ declaringClass , $ methodReflection ->getName (), array_map (static function (\ReflectionParameter $ parameter ): string {
495
497
return $ parameter ->getName ();
496
498
}, $ methodReflection ->getParameters ()));
499
+ $ phpDocBlockClassReflection = $ declaringClass ;
500
+ if ($ stubPhpDocPair !== null ) {
501
+ [$ resolvedPhpDoc , $ phpDocBlockClassReflection ] = $ stubPhpDocPair ;
502
+ }
497
503
$ stubPhpDocString = null ;
498
504
$ phpDocBlock = null ;
499
505
if ($ resolvedPhpDoc === null ) {
@@ -526,7 +532,6 @@ private function createMethod(
526
532
}
527
533
}
528
534
} else {
529
- $ phpDocBlockClassReflection = $ declaringClass ;
530
535
$ isPhpDocBlockExplicit = true ;
531
536
$ stubPhpDocString = $ resolvedPhpDoc ->getPhpDocString ();
532
537
}
@@ -547,7 +552,7 @@ private function createMethod(
547
552
$ isInternal = false ;
548
553
$ isFinal = false ;
549
554
if ($ resolvedPhpDoc !== null ) {
550
- if (!isset ($ phpDocBlockClassReflection ) || ! isset ( $ isPhpDocBlockExplicit )) {
555
+ if (!isset ($ isPhpDocBlockExplicit )) {
551
556
throw new \PHPStan \ShouldNotHappenException ();
552
557
}
553
558
$ templateTypeMap = $ resolvedPhpDoc ->getTemplateTypeMap ();
@@ -883,25 +888,23 @@ private function getPhpDocReturnType(ClassReflection $phpDocBlockClassReflection
883
888
}
884
889
885
890
/**
886
- * @param string $declaringClassName
891
+ * @param ClassReflection $declaringClass
887
892
* @param string $methodName
888
893
* @param array<int, string> $positionalParameterNames
889
- * @return \PHPStan\PhpDoc\ResolvedPhpDocBlock|null
894
+ * @return array{ \PHPStan\PhpDoc\ResolvedPhpDocBlock, ClassReflection} |null
890
895
*/
891
- private function findMethodPhpDocIncludingAncestors (string $ declaringClassName , string $ methodName , array $ positionalParameterNames ): ?ResolvedPhpDocBlock
896
+ private function findMethodPhpDocIncludingAncestors (ClassReflection $ declaringClass , string $ methodName , array $ positionalParameterNames ): ?array
892
897
{
898
+ $ declaringClassName = $ declaringClass ->getName ();
893
899
$ resolved = $ this ->stubPhpDocProvider ->findMethodPhpDoc ($ declaringClassName , $ methodName , $ positionalParameterNames );
894
900
if ($ resolved !== null ) {
895
- return $ resolved ;
901
+ return [ $ resolved, $ declaringClass ] ;
896
902
}
897
903
if (!$ this ->stubPhpDocProvider ->isKnownClass ($ declaringClassName )) {
898
904
return null ;
899
905
}
900
- if (!$ this ->reflectionProvider ->hasClass ($ declaringClassName )) {
901
- return null ;
902
- }
903
906
904
- $ ancestors = $ this -> reflectionProvider -> getClass ( $ declaringClassName ) ->getAncestors ();
907
+ $ ancestors = $ declaringClass ->getAncestors ();
905
908
foreach ($ ancestors as $ ancestor ) {
906
909
if ($ ancestor ->getName () === $ declaringClassName ) {
907
910
continue ;
@@ -915,7 +918,7 @@ private function findMethodPhpDocIncludingAncestors(string $declaringClassName,
915
918
continue ;
916
919
}
917
920
918
- return $ resolved ;
921
+ return [ $ resolved, $ ancestor ] ;
919
922
}
920
923
921
924
return null ;
0 commit comments