10
10
use PHPStan \Analyser \NodeScopeResolver ;
11
11
use PHPStan \Analyser \ScopeContext ;
12
12
use PHPStan \Analyser \ScopeFactory ;
13
+ use PHPStan \BetterReflection \Reflection \Adapter \ReflectionMethod ;
13
14
use PHPStan \BetterReflection \Reflection \Adapter \ReflectionParameter ;
14
15
use PHPStan \BetterReflection \Reflection \Adapter \ReflectionProperty ;
15
16
use PHPStan \Parser \Parser ;
@@ -384,7 +385,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
384
385
return $ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ methodName ];
385
386
}
386
387
387
- $ nativeMethodReflection = new NativeBuiltinMethodReflection ( $ classReflection ->getNativeReflection ()->getMethod ($ methodName) );
388
+ $ nativeMethodReflection = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
388
389
if (!isset ($ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()])) {
389
390
$ method = $ this ->createMethod ($ classReflection , $ nativeMethodReflection , true );
390
391
$ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()] = $ method ;
@@ -411,8 +412,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
411
412
throw new ShouldNotHappenException ();
412
413
}
413
414
414
- $ reflectionMethod = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
415
- $ nativeMethodReflection = new NativeBuiltinMethodReflection ($ reflectionMethod );
415
+ $ nativeMethodReflection = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
416
416
417
417
if (!isset ($ this ->nativeMethods [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()])) {
418
418
$ method = $ this ->createMethod ($ classReflection , $ nativeMethodReflection , false );
@@ -424,7 +424,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
424
424
425
425
private function createMethod (
426
426
ClassReflection $ classReflection ,
427
- BuiltinMethodReflection $ methodReflection ,
427
+ ReflectionMethod $ methodReflection ,
428
428
bool $ includingAnnotations ,
429
429
): ExtendedMethodReflection
430
430
{
@@ -642,27 +642,25 @@ private function createMethod(
642
642
);
643
643
}
644
644
645
- public function createUserlandMethodReflection (ClassReflection $ fileDeclaringClass , ClassReflection $ actualDeclaringClass , BuiltinMethodReflection $ methodReflection , ?string $ declaringTraitName ): PhpMethodReflection
645
+ public function createUserlandMethodReflection (ClassReflection $ fileDeclaringClass , ClassReflection $ actualDeclaringClass , ReflectionMethod $ methodReflection , ?string $ declaringTraitName ): PhpMethodReflection
646
646
{
647
647
$ resolvedPhpDoc = null ;
648
648
$ stubPhpDocPair = $ this ->findMethodPhpDocIncludingAncestors ($ fileDeclaringClass , $ fileDeclaringClass , $ methodReflection ->getName (), array_map (static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (), $ methodReflection ->getParameters ()));
649
649
$ phpDocBlockClassReflection = $ fileDeclaringClass ;
650
650
651
- if ($ methodReflection ->getReflection () !== null ) {
652
- $ methodDeclaringClass = $ methodReflection ->getReflection ()->getBetterReflection ()->getDeclaringClass ();
653
-
654
- if ($ stubPhpDocPair === null && $ methodDeclaringClass ->isTrait ()) {
655
- if (! $ methodReflection ->getDeclaringClass ()->isTrait () || $ methodDeclaringClass ->getName () !== $ methodReflection ->getDeclaringClass ()->getName ()) {
656
- $ stubPhpDocPair = $ this ->findMethodPhpDocIncludingAncestors (
657
- $ this ->reflectionProviderProvider ->getReflectionProvider ()->getClass ($ methodDeclaringClass ->getName ()),
658
- $ this ->reflectionProviderProvider ->getReflectionProvider ()->getClass ($ methodReflection ->getDeclaringClass ()->getName ()),
659
- $ methodReflection ->getName (),
660
- array_map (
661
- static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (),
662
- $ methodReflection ->getParameters (),
663
- ),
664
- );
665
- }
651
+ $ methodDeclaringClass = $ methodReflection ->getBetterReflection ()->getDeclaringClass ();
652
+
653
+ if ($ stubPhpDocPair === null && $ methodDeclaringClass ->isTrait ()) {
654
+ if (! $ methodReflection ->getDeclaringClass ()->isTrait () || $ methodDeclaringClass ->getName () !== $ methodReflection ->getDeclaringClass ()->getName ()) {
655
+ $ stubPhpDocPair = $ this ->findMethodPhpDocIncludingAncestors (
656
+ $ this ->reflectionProviderProvider ->getReflectionProvider ()->getClass ($ methodDeclaringClass ->getName ()),
657
+ $ this ->reflectionProviderProvider ->getReflectionProvider ()->getClass ($ methodReflection ->getDeclaringClass ()->getName ()),
658
+ $ methodReflection ->getName (),
659
+ array_map (
660
+ static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (),
661
+ $ methodReflection ->getParameters (),
662
+ ),
663
+ );
666
664
}
667
665
}
668
666
@@ -671,7 +669,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
671
669
}
672
670
673
671
if ($ resolvedPhpDoc === null ) {
674
- $ docComment = $ methodReflection ->getDocComment ();
672
+ $ docComment = $ methodReflection ->getDocComment () !== false ? $ methodReflection -> getDocComment () : null ;
675
673
$ positionalParameterNames = array_map (static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (), $ methodReflection ->getParameters ());
676
674
677
675
$ resolvedPhpDoc = $ this ->phpDocInheritanceResolver ->resolvePhpDocForMethod (
@@ -694,10 +692,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
694
692
}
695
693
696
694
$ phpDocParameterTypes = [];
697
- if (
698
- $ methodReflection instanceof NativeBuiltinMethodReflection
699
- && $ methodReflection ->isConstructor ()
700
- ) {
695
+ if ($ methodReflection ->isConstructor ()) {
701
696
foreach ($ methodReflection ->getParameters () as $ parameter ) {
702
697
if (!$ parameter ->isPromoted ()) {
703
698
continue ;
@@ -922,14 +917,10 @@ private function findPropertyTrait(ReflectionProperty $propertyReflection): ?str
922
917
}
923
918
924
919
private function findMethodTrait (
925
- BuiltinMethodReflection $ methodReflection ,
920
+ ReflectionMethod $ methodReflection ,
926
921
): ?string
927
922
{
928
- if ($ methodReflection ->getReflection () === null ) {
929
- return null ;
930
- }
931
-
932
- $ declaringClass = $ methodReflection ->getReflection ()->getBetterReflection ()->getDeclaringClass ();
923
+ $ declaringClass = $ methodReflection ->getBetterReflection ()->getDeclaringClass ();
933
924
if ($ declaringClass ->isTrait ()) {
934
925
if ($ methodReflection ->getDeclaringClass ()->isTrait () && $ declaringClass ->getName () === $ methodReflection ->getDeclaringClass ()->getName ()) {
935
926
return null ;
0 commit comments