@@ -2335,12 +2335,31 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
2335
2335
return new ErrorType ();
2336
2336
}
2337
2337
2338
- return ParametersAcceptorSelector::selectFromArgs (
2338
+ $ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs (
2339
2339
$ this ,
2340
2340
$ node ->getArgs (),
2341
2341
$ calledOnType ->getCallableParametersAcceptors ($ this ),
2342
2342
null ,
2343
- )->getReturnType ();
2343
+ );
2344
+
2345
+ $ functionName = null ;
2346
+ if ($ node ->name instanceof String_) {
2347
+ /** @var non-empty-string $name */
2348
+ $ name = $ node ->name ->value ;
2349
+ $ functionName = new Name ($ name );
2350
+ } elseif ($ node ->name instanceof FuncCall && $ node ->name ->name instanceof Name) {
2351
+ $ functionName = $ node ->name ->name ;
2352
+ }
2353
+
2354
+ if ($ functionName !== null && $ this ->reflectionProvider ->hasFunction ($ functionName , $ this )) {
2355
+ $ functionReflection = $ this ->reflectionProvider ->getFunction ($ functionName , $ this );
2356
+ $ resolvedType = $ this ->getDynamicFunctionReturnType ($ parametersAcceptor , $ node , $ functionReflection );
2357
+ if ($ resolvedType !== null ) {
2358
+ return $ resolvedType ;
2359
+ }
2360
+ }
2361
+
2362
+ return $ parametersAcceptor ->getReturnType ();
2344
2363
}
2345
2364
2346
2365
if (!$ this ->reflectionProvider ->hasFunction ($ node ->name , $ this )) {
@@ -2369,19 +2388,9 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
2369
2388
);
2370
2389
$ normalizedNode = ArgumentsNormalizer::reorderFuncArguments ($ parametersAcceptor , $ node );
2371
2390
if ($ normalizedNode !== null ) {
2372
- foreach ($ this ->dynamicReturnTypeExtensionRegistry ->getDynamicFunctionReturnTypeExtensions () as $ dynamicFunctionReturnTypeExtension ) {
2373
- if (!$ dynamicFunctionReturnTypeExtension ->isFunctionSupported ($ functionReflection )) {
2374
- continue ;
2375
- }
2376
-
2377
- $ resolvedType = $ dynamicFunctionReturnTypeExtension ->getTypeFromFunctionCall (
2378
- $ functionReflection ,
2379
- $ normalizedNode ,
2380
- $ this ,
2381
- );
2382
- if ($ resolvedType !== null ) {
2383
- return $ resolvedType ;
2384
- }
2391
+ $ resolvedType = $ this ->getDynamicFunctionReturnType ($ parametersAcceptor , $ normalizedNode , $ functionReflection );
2392
+ if ($ resolvedType !== null ) {
2393
+ return $ resolvedType ;
2385
2394
}
2386
2395
}
2387
2396
@@ -2391,6 +2400,29 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
2391
2400
return new MixedType ();
2392
2401
}
2393
2402
2403
+ private function getDynamicFunctionReturnType (ParametersAcceptor $ parametersAcceptor , FuncCall $ node , FunctionReflection $ functionReflection ): ?Type
2404
+ {
2405
+ $ normalizedNode = ArgumentsNormalizer::reorderFuncArguments ($ parametersAcceptor , $ node );
2406
+ if ($ normalizedNode !== null ) {
2407
+ foreach ($ this ->dynamicReturnTypeExtensionRegistry ->getDynamicFunctionReturnTypeExtensions () as $ dynamicFunctionReturnTypeExtension ) {
2408
+ if (!$ dynamicFunctionReturnTypeExtension ->isFunctionSupported ($ functionReflection )) {
2409
+ continue ;
2410
+ }
2411
+
2412
+ $ resolvedType = $ dynamicFunctionReturnTypeExtension ->getTypeFromFunctionCall (
2413
+ $ functionReflection ,
2414
+ $ node ,
2415
+ $ this ,
2416
+ );
2417
+ if ($ resolvedType !== null ) {
2418
+ return $ resolvedType ;
2419
+ }
2420
+ }
2421
+ }
2422
+
2423
+ return null ;
2424
+ }
2425
+
2394
2426
private function getNullsafeShortCircuitingType (Expr $ expr , Type $ type ): Type
2395
2427
{
2396
2428
if ($ expr instanceof Expr \NullsafePropertyFetch || $ expr instanceof Expr \NullsafeMethodCall) {
0 commit comments