1010use PHPStan \Analyser \NodeScopeResolver ;
1111use PHPStan \Analyser \ScopeContext ;
1212use PHPStan \Analyser \ScopeFactory ;
13+ use PHPStan \BetterReflection \Reflection \Adapter \ReflectionMethod ;
1314use PHPStan \BetterReflection \Reflection \Adapter \ReflectionParameter ;
1415use PHPStan \BetterReflection \Reflection \Adapter \ReflectionProperty ;
1516use PHPStan \Parser \Parser ;
@@ -384,7 +385,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
384385 return $ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ methodName ];
385386 }
386387
387- $ nativeMethodReflection = new NativeBuiltinMethodReflection ( $ classReflection ->getNativeReflection ()->getMethod ($ methodName) );
388+ $ nativeMethodReflection = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
388389 if (!isset ($ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()])) {
389390 $ method = $ this ->createMethod ($ classReflection , $ nativeMethodReflection , true );
390391 $ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()] = $ method ;
@@ -411,8 +412,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
411412 throw new ShouldNotHappenException ();
412413 }
413414
414- $ reflectionMethod = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
415- $ nativeMethodReflection = new NativeBuiltinMethodReflection ($ reflectionMethod );
415+ $ nativeMethodReflection = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
416416
417417 if (!isset ($ this ->nativeMethods [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()])) {
418418 $ method = $ this ->createMethod ($ classReflection , $ nativeMethodReflection , false );
@@ -424,7 +424,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
424424
425425 private function createMethod (
426426 ClassReflection $ classReflection ,
427- BuiltinMethodReflection $ methodReflection ,
427+ ReflectionMethod $ methodReflection ,
428428 bool $ includingAnnotations ,
429429 ): ExtendedMethodReflection
430430 {
@@ -642,27 +642,25 @@ private function createMethod(
642642 );
643643 }
644644
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
646646 {
647647 $ resolvedPhpDoc = null ;
648648 $ stubPhpDocPair = $ this ->findMethodPhpDocIncludingAncestors ($ fileDeclaringClass , $ fileDeclaringClass , $ methodReflection ->getName (), array_map (static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (), $ methodReflection ->getParameters ()));
649649 $ phpDocBlockClassReflection = $ fileDeclaringClass ;
650650
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+ );
666664 }
667665 }
668666
@@ -671,7 +669,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
671669 }
672670
673671 if ($ resolvedPhpDoc === null ) {
674- $ docComment = $ methodReflection ->getDocComment ();
672+ $ docComment = $ methodReflection ->getDocComment () !== false ? $ methodReflection -> getDocComment () : null ;
675673 $ positionalParameterNames = array_map (static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (), $ methodReflection ->getParameters ());
676674
677675 $ resolvedPhpDoc = $ this ->phpDocInheritanceResolver ->resolvePhpDocForMethod (
@@ -694,10 +692,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
694692 }
695693
696694 $ phpDocParameterTypes = [];
697- if (
698- $ methodReflection instanceof NativeBuiltinMethodReflection
699- && $ methodReflection ->isConstructor ()
700- ) {
695+ if ($ methodReflection ->isConstructor ()) {
701696 foreach ($ methodReflection ->getParameters () as $ parameter ) {
702697 if (!$ parameter ->isPromoted ()) {
703698 continue ;
@@ -922,14 +917,10 @@ private function findPropertyTrait(ReflectionProperty $propertyReflection): ?str
922917 }
923918
924919 private function findMethodTrait (
925- BuiltinMethodReflection $ methodReflection ,
920+ ReflectionMethod $ methodReflection ,
926921 ): ?string
927922 {
928- if ($ methodReflection ->getReflection () === null ) {
929- return null ;
930- }
931-
932- $ declaringClass = $ methodReflection ->getReflection ()->getBetterReflection ()->getDeclaringClass ();
923+ $ declaringClass = $ methodReflection ->getBetterReflection ()->getDeclaringClass ();
933924 if ($ declaringClass ->isTrait ()) {
934925 if ($ methodReflection ->getDeclaringClass ()->isTrait () && $ declaringClass ->getName () === $ methodReflection ->getDeclaringClass ()->getName ()) {
935926 return null ;
0 commit comments