@@ -414,6 +414,15 @@ private function createMethod(
414414
415415 $ stubPhpDocString = null ;
416416 $ variants = [];
417+ $ reflectionMethod = null ;
418+ if (class_exists ($ classReflection ->getName (), false )) {
419+ $ reflectionClass = new \ReflectionClass ($ classReflection ->getName ());
420+ if ($ reflectionClass ->hasMethod ($ methodReflection ->getName ())) {
421+ $ reflectionMethod = $ reflectionClass ->getMethod ($ methodReflection ->getName ());
422+ }
423+ } else {
424+ $ reflectionMethod = $ classReflection ->getNativeReflection ()->getMethod ($ methodReflection ->getName ());
425+ }
417426 foreach ($ variantNames as $ innerVariantName ) {
418427 $ methodSignature = $ this ->signatureMapProvider ->getFunctionSignature ($ innerVariantName , $ declaringClassName );
419428 $ phpDocReturnType = null ;
@@ -445,7 +454,7 @@ private function createMethod(
445454 }
446455 }
447456 }
448- $ variants [] = $ this ->createNativeMethodVariant ($ methodSignature , $ stubPhpDocParameterTypes , $ stubPhpDocParameterVariadicity , $ phpDocReturnType );
457+ $ variants [] = $ this ->createNativeMethodVariant ($ methodSignature , $ stubPhpDocParameterTypes , $ stubPhpDocParameterVariadicity , $ phpDocReturnType, $ reflectionMethod );
449458 }
450459
451460 if ($ this ->signatureMapProvider ->hasFunctionMetadata ($ signatureMapMethodName )) {
@@ -552,23 +561,49 @@ private function createMethod(
552561 * @param array<string, Type> $stubPhpDocParameterTypes
553562 * @param array<string, bool> $stubPhpDocParameterVariadicity
554563 * @param Type|null $phpDocReturnType
564+ * @param \ReflectionMethod|null $reflectionMethod
555565 * @return FunctionVariantWithPhpDocs
556566 */
557567 private function createNativeMethodVariant (
558568 FunctionSignature $ methodSignature ,
559569 array $ stubPhpDocParameterTypes ,
560570 array $ stubPhpDocParameterVariadicity ,
561- ?Type $ phpDocReturnType
571+ ?Type $ phpDocReturnType ,
572+ ?\ReflectionMethod $ reflectionMethod
562573 ): FunctionVariantWithPhpDocs
563574 {
564575 $ parameters = [];
565- foreach ($ methodSignature ->getParameters () as $ parameterSignature ) {
576+ $ nativeParameters = null ;
577+ $ nativeReturnType = null ;
578+ if ($ reflectionMethod !== null ) {
579+ $ nativeParameters = $ reflectionMethod ->getParameters ();
580+ $ nativeReturnType = TypehintHelper::decideTypeFromReflection (
581+ $ reflectionMethod ->getReturnType (),
582+ null ,
583+ null ,
584+ false
585+ );
586+ }
587+ foreach ($ methodSignature ->getParameters () as $ i => $ parameterSignature ) {
588+ if (
589+ $ nativeParameters !== null
590+ && array_key_exists ($ i , $ nativeParameters )
591+ ) {
592+ $ nativeParameterType = TypehintHelper::decideTypeFromReflection (
593+ $ nativeParameters [$ i ]->getType (),
594+ null ,
595+ null ,
596+ $ nativeParameters [$ i ]->isVariadic ()
597+ );
598+ } else {
599+ $ nativeParameterType = new MixedType ();
600+ }
566601 $ parameters [] = new NativeParameterWithPhpDocsReflection (
567602 $ parameterSignature ->getName (),
568603 $ parameterSignature ->isOptional (),
569604 $ stubPhpDocParameterTypes [$ parameterSignature ->getName ()] ?? $ parameterSignature ->getType (),
570605 $ stubPhpDocParameterTypes [$ parameterSignature ->getName ()] ?? new MixedType (),
571- new MixedType ( true ), // todo
606+ $ nativeParameterType ,
572607 $ parameterSignature ->passedByReference (),
573608 $ stubPhpDocParameterVariadicity [$ parameterSignature ->getName ()] ?? $ parameterSignature ->isVariadic (),
574609 null ,
@@ -583,7 +618,7 @@ private function createNativeMethodVariant(
583618 $ methodSignature ->isVariadic (),
584619 $ phpDocReturnType ?? $ methodSignature ->getReturnType (),
585620 $ phpDocReturnType ?? new MixedType (),
586- new MixedType ( true ) // todo $methodSignature->getNativeReturnType ()
621+ $ nativeReturnType ?? new MixedType ()
587622 );
588623 }
589624
0 commit comments