1010use PHPStan \Analyser \NodeScopeResolver ;
1111use PHPStan \Analyser \ScopeContext ;
1212use PHPStan \Analyser \ScopeFactory ;
13- use PHPStan \BetterReflection \Reflection \Adapter \ReflectionMethod ;
1413use PHPStan \BetterReflection \Reflection \Adapter \ReflectionParameter ;
1514use PHPStan \BetterReflection \Reflection \Adapter \ReflectionProperty ;
1615use PHPStan \Parser \Parser ;
@@ -381,7 +380,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
381380 return $ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ methodName ];
382381 }
383382
384- $ nativeMethodReflection = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
383+ $ nativeMethodReflection = new NativeBuiltinMethodReflection ( $ classReflection ->getNativeReflection ()->getMethod ($ methodName) );
385384 if (!isset ($ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()])) {
386385 $ method = $ this ->createMethod ($ classReflection , $ nativeMethodReflection , true );
387386 $ this ->methodsIncludingAnnotations [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()] = $ method ;
@@ -408,7 +407,8 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
408407 throw new ShouldNotHappenException ();
409408 }
410409
411- $ nativeMethodReflection = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
410+ $ reflectionMethod = $ classReflection ->getNativeReflection ()->getMethod ($ methodName );
411+ $ nativeMethodReflection = new NativeBuiltinMethodReflection ($ reflectionMethod );
412412
413413 if (!isset ($ this ->nativeMethods [$ classReflection ->getCacheKey ()][$ nativeMethodReflection ->getName ()])) {
414414 $ method = $ this ->createMethod ($ classReflection , $ nativeMethodReflection , false );
@@ -420,7 +420,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
420420
421421 private function createMethod (
422422 ClassReflection $ classReflection ,
423- ReflectionMethod $ methodReflection ,
423+ BuiltinMethodReflection $ methodReflection ,
424424 bool $ includingAnnotations ,
425425 ): ExtendedMethodReflection
426426 {
@@ -621,14 +621,14 @@ private function createMethod(
621621 return $ this ->createUserlandMethodReflection ($ declaringClass , $ declaringClass , $ methodReflection );
622622 }
623623
624- public function createUserlandMethodReflection (ClassReflection $ fileDeclaringClass , ClassReflection $ actualDeclaringClass , ReflectionMethod $ methodReflection ): PhpMethodReflection
624+ public function createUserlandMethodReflection (ClassReflection $ fileDeclaringClass , ClassReflection $ actualDeclaringClass , BuiltinMethodReflection $ methodReflection ): PhpMethodReflection
625625 {
626626 $ declaringTraitName = $ this ->findMethodTrait ($ methodReflection );
627627 $ resolvedPhpDoc = null ;
628628 $ stubPhpDocPair = $ this ->findMethodPhpDocIncludingAncestors ($ fileDeclaringClass , $ methodReflection ->getName (), array_map (static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (), $ methodReflection ->getParameters ()));
629629 $ phpDocBlockClassReflection = $ fileDeclaringClass ;
630630
631- $ methodDeclaringClass = $ methodReflection ->getBetterReflection ()->getDeclaringClass ();
631+ $ methodDeclaringClass = $ methodReflection ->getReflection ()-> getBetterReflection ()->getDeclaringClass ();
632632
633633 if ($ stubPhpDocPair === null && $ methodDeclaringClass ->isTrait ()) {
634634 if (! $ methodReflection ->getDeclaringClass ()->isTrait () || $ methodDeclaringClass ->getName () !== $ methodReflection ->getDeclaringClass ()->getName ()) {
@@ -648,7 +648,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
648648 }
649649
650650 if ($ resolvedPhpDoc === null ) {
651- $ docComment = $ methodReflection ->getDocComment () !== false ? $ methodReflection -> getDocComment () : null ;
651+ $ docComment = $ methodReflection ->getDocComment ();
652652 $ positionalParameterNames = array_map (static fn (ReflectionParameter $ parameter ): string => $ parameter ->getName (), $ methodReflection ->getParameters ());
653653
654654 $ resolvedPhpDoc = $ this ->phpDocInheritanceResolver ->resolvePhpDocForMethod (
@@ -671,7 +671,10 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
671671 }
672672
673673 $ phpDocParameterTypes = [];
674- if ($ methodReflection ->isConstructor ()) {
674+ if (
675+ $ methodReflection instanceof NativeBuiltinMethodReflection
676+ && $ methodReflection ->isConstructor ()
677+ ) {
675678 foreach ($ methodReflection ->getParameters () as $ parameter ) {
676679 if (!$ parameter ->isPromoted ()) {
677680 continue ;
@@ -862,10 +865,10 @@ private function findPropertyTrait(ReflectionProperty $propertyReflection): ?str
862865 }
863866
864867 private function findMethodTrait (
865- ReflectionMethod $ methodReflection ,
868+ BuiltinMethodReflection $ methodReflection ,
866869 ): ?string
867870 {
868- $ declaringClass = $ methodReflection ->getBetterReflection ()->getDeclaringClass ();
871+ $ declaringClass = $ methodReflection ->getReflection ()-> getBetterReflection ()->getDeclaringClass ();
869872 if ($ declaringClass ->isTrait ()) {
870873 if ($ methodReflection ->getDeclaringClass ()->isTrait () && $ declaringClass ->getName () === $ methodReflection ->getDeclaringClass ()->getName ()) {
871874 return null ;
0 commit comments