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 ;
@@ -380,7 +381,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
380381 return $ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ methodName ];
381382 }
382383
383- $ nativeMethodReflection = new NativeBuiltinMethodReflection ( $ classReflection ->getNativeReflection ()->getMethod ($ methodName) );
384+ $ nativeMethodReflection = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
384385 if (!isset ($ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()])) {
385386 $ method = $ this ->createMethod ($ classReflection , $ nativeMethodReflection , true );
386387 $ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()] = $ method ;
@@ -407,9 +408,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
407408 throw new ShouldNotHappenException ();
408409 }
409410
410- $ nativeMethodReflection = new NativeBuiltinMethodReflection (
411- $ classReflection ->getNativeReflection ()->getMethod ($ methodName ),
412- );
411+ $ nativeMethodReflection = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
413412
414413 if (!isset ($ this ->nativeMethods [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()])) {
415414 $ method = $ this ->createMethod ($ classReflection , $ nativeMethodReflection , false );
@@ -421,7 +420,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
421420
422421 private function createMethod (
423422 ClassReflection $ classReflection ,
424- BuiltinMethodReflection $ methodReflection ,
423+ ReflectionMethod $ methodReflection ,
425424 bool $ includingAnnotations ,
426425 ): ExtendedMethodReflection
427426 {
@@ -624,20 +623,18 @@ private function createMethod(
624623 $ stubPhpDocPair = $ this ->findMethodPhpDocIncludingAncestors ($ declaringClass , $ methodReflection ->getName (), array_map (static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (), $ methodReflection ->getParameters ()));
625624 $ phpDocBlockClassReflection = $ declaringClass ;
626625
627- if ($ methodReflection ->getReflection () !== null ) {
628- $ methodDeclaringClass = $ methodReflection ->getReflection ()->getBetterReflection ()->getDeclaringClass ();
629-
630- if ($ stubPhpDocPair === null && $ methodDeclaringClass ->isTrait ()) {
631- if (! $ methodReflection ->getDeclaringClass ()->isTrait () || $ methodDeclaringClass ->getName () !== $ methodReflection ->getDeclaringClass ()->getName ()) {
632- $ stubPhpDocPair = $ this ->findMethodPhpDocIncludingAncestors (
633- $ this ->reflectionProviderProvider ->getReflectionProvider ()->getClass ($ methodDeclaringClass ->getName ()),
634- $ methodReflection ->getName (),
635- array_map (
636- static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (),
637- $ methodReflection ->getParameters (),
638- ),
639- );
640- }
626+ $ methodDeclaringClass = $ methodReflection ->getBetterReflection ()->getDeclaringClass ();
627+
628+ if ($ stubPhpDocPair === null && $ methodDeclaringClass ->isTrait ()) {
629+ if (! $ methodReflection ->getDeclaringClass ()->isTrait () || $ methodDeclaringClass ->getName () !== $ methodReflection ->getDeclaringClass ()->getName ()) {
630+ $ stubPhpDocPair = $ this ->findMethodPhpDocIncludingAncestors (
631+ $ this ->reflectionProviderProvider ->getReflectionProvider ()->getClass ($ methodDeclaringClass ->getName ()),
632+ $ methodReflection ->getName (),
633+ array_map (
634+ static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (),
635+ $ methodReflection ->getParameters (),
636+ ),
637+ );
641638 }
642639 }
643640
@@ -646,7 +643,7 @@ private function createMethod(
646643 }
647644
648645 if ($ resolvedPhpDoc === null ) {
649- $ docComment = $ methodReflection ->getDocComment ();
646+ $ docComment = $ methodReflection ->getDocComment () !== false ? $ methodReflection -> getDocComment () : null ;
650647 $ positionalParameterNames = array_map (static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (), $ methodReflection ->getParameters ());
651648
652649 $ resolvedPhpDoc = $ this ->phpDocInheritanceResolver ->resolvePhpDocForMethod (
@@ -669,10 +666,7 @@ private function createMethod(
669666 }
670667
671668 $ phpDocParameterTypes = [];
672- if (
673- $ methodReflection instanceof NativeBuiltinMethodReflection
674- && $ methodReflection ->isConstructor ()
675- ) {
669+ if ($ methodReflection ->isConstructor ()) {
676670 foreach ($ methodReflection ->getParameters () as $ parameter ) {
677671 if (!$ parameter ->isPromoted ()) {
678672 continue ;
@@ -863,14 +857,10 @@ private function findPropertyTrait(ReflectionProperty $propertyReflection): ?str
863857 }
864858
865859 private function findMethodTrait (
866- BuiltinMethodReflection $ methodReflection ,
860+ ReflectionMethod $ methodReflection ,
867861 ): ?string
868862 {
869- if ($ methodReflection ->getReflection () === null ) {
870- return null ;
871- }
872-
873- $ declaringClass = $ methodReflection ->getReflection ()->getBetterReflection ()->getDeclaringClass ();
863+ $ declaringClass = $ methodReflection ->getBetterReflection ()->getDeclaringClass ();
874864 if ($ declaringClass ->isTrait ()) {
875865 if ($ methodReflection ->getDeclaringClass ()->isTrait () && $ declaringClass ->getName () === $ methodReflection ->getDeclaringClass ()->getName ()) {
876866 return null ;
0 commit comments