2929use PHPStan \Reflection \Php \PhpClassReflectionExtension ;
3030use PHPStan \Reflection \Php \PhpPropertyReflection ;
3131use PHPStan \Reflection \Php \UniversalObjectCratesClassReflectionExtension ;
32+ use PHPStan \Reflection \RequireExtension \RequireExtendsMethodsClassReflectionExtension ;
33+ use PHPStan \Reflection \RequireExtension \RequireExtendsPropertiesClassReflectionExtension ;
3234use PHPStan \Reflection \SignatureMap \SignatureMapProvider ;
3335use PHPStan \ShouldNotHappenException ;
3436use PHPStan \Type \CircularTypeAliasDefinitionException ;
@@ -146,6 +148,8 @@ public function __construct(
146148 private array $ propertiesClassReflectionExtensions ,
147149 private array $ methodsClassReflectionExtensions ,
148150 private array $ allowedSubTypesClassReflectionExtensions ,
151+ private RequireExtendsPropertiesClassReflectionExtension $ requireExtendsPropertiesClassReflectionExtension ,
152+ private RequireExtendsMethodsClassReflectionExtension $ requireExtendsMethodsClassReflectionExtension ,
149153 private string $ displayName ,
150154 private ReflectionClass |ReflectionEnum $ reflection ,
151155 private ?string $ anonymousFilename ,
@@ -435,6 +439,10 @@ public function hasProperty(string $propertyName): bool
435439 }
436440 }
437441
442+ if ($ this ->requireExtendsPropertiesClassReflectionExtension ->hasProperty ($ this , $ propertyName )) {
443+ return true ;
444+ }
445+
438446 return false ;
439447 }
440448
@@ -446,6 +454,10 @@ public function hasMethod(string $methodName): bool
446454 }
447455 }
448456
457+ if ($ this ->requireExtendsMethodsClassReflectionExtension ->hasMethod ($ this , $ methodName )) {
458+ return true ;
459+ }
460+
449461 return false ;
450462 }
451463
@@ -455,6 +467,7 @@ public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope):
455467 if ($ scope ->isInClass ()) {
456468 $ key = sprintf ('%s-%s ' , $ key , $ scope ->getClassReflection ()->getCacheKey ());
457469 }
470+
458471 if (!isset ($ this ->methods [$ key ])) {
459472 foreach ($ this ->methodsClassReflectionExtensions as $ extension ) {
460473 if (!$ extension ->hasMethod ($ this , $ methodName )) {
@@ -469,6 +482,13 @@ public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope):
469482 }
470483 }
471484
485+ if (!isset ($ this ->methods [$ key ])) {
486+ if ($ this ->requireExtendsMethodsClassReflectionExtension ->hasMethod ($ this , $ methodName )) {
487+ $ method = $ this ->requireExtendsMethodsClassReflectionExtension ->getMethod ($ this , $ methodName );
488+ $ this ->methods [$ key ] = $ method ;
489+ }
490+ }
491+
472492 if (!isset ($ this ->methods [$ key ])) {
473493 throw new MissingMethodFromReflectionException ($ this ->getName (), $ methodName );
474494 }
@@ -577,11 +597,13 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
577597 if ($ scope ->isInClass ()) {
578598 $ key = sprintf ('%s-%s ' , $ key , $ scope ->getClassReflection ()->getCacheKey ());
579599 }
600+
580601 if (!isset ($ this ->properties [$ key ])) {
581602 foreach ($ this ->propertiesClassReflectionExtensions as $ i => $ extension ) {
582603 if ($ i > 0 && !$ this ->allowsDynamicPropertiesExtensions ()) {
583604 break ;
584605 }
606+
585607 if (!$ extension ->hasProperty ($ this , $ propertyName )) {
586608 continue ;
587609 }
@@ -594,6 +616,13 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
594616 }
595617 }
596618
619+ if (!isset ($ this ->properties [$ key ])) {
620+ if ($ this ->requireExtendsPropertiesClassReflectionExtension ->hasProperty ($ this , $ propertyName )) {
621+ $ property = $ this ->requireExtendsPropertiesClassReflectionExtension ->getProperty ($ this , $ propertyName );
622+ $ this ->properties [$ key ] = $ property ;
623+ }
624+ }
625+
597626 if (!isset ($ this ->properties [$ key ])) {
598627 throw new MissingPropertyFromReflectionException ($ this ->getName (), $ propertyName );
599628 }
@@ -1410,6 +1439,8 @@ public function withTypes(array $types): self
14101439 $ this ->propertiesClassReflectionExtensions ,
14111440 $ this ->methodsClassReflectionExtensions ,
14121441 $ this ->allowedSubTypesClassReflectionExtensions ,
1442+ $ this ->requireExtendsPropertiesClassReflectionExtension ,
1443+ $ this ->requireExtendsMethodsClassReflectionExtension ,
14131444 $ this ->displayName ,
14141445 $ this ->reflection ,
14151446 $ this ->anonymousFilename ,
@@ -1437,6 +1468,8 @@ public function withVariances(array $variances): self
14371468 $ this ->propertiesClassReflectionExtensions ,
14381469 $ this ->methodsClassReflectionExtensions ,
14391470 $ this ->allowedSubTypesClassReflectionExtensions ,
1471+ $ this ->requireExtendsPropertiesClassReflectionExtension ,
1472+ $ this ->requireExtendsMethodsClassReflectionExtension ,
14401473 $ this ->displayName ,
14411474 $ this ->reflection ,
14421475 $ this ->anonymousFilename ,
0 commit comments