@@ -2329,36 +2329,44 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
2329
2329
}
2330
2330
2331
2331
if ($ node instanceof FuncCall) {
2332
- $ functionName = null ;
2333
- if ($ node ->name instanceof Name) {
2334
- $ functionName = $ node ->name ;
2335
- } elseif ($ node ->name instanceof Expr) {
2332
+ if ($ node ->name instanceof Expr) {
2336
2333
$ calledOnType = $ this ->getType ($ node ->name );
2337
2334
if ($ calledOnType ->isCallable ()->no ()) {
2338
2335
return new ErrorType ();
2339
2336
}
2340
2337
2338
+ $ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs (
2339
+ $ this ,
2340
+ $ node ->getArgs (),
2341
+ $ calledOnType ->getCallableParametersAcceptors ($ this ),
2342
+ null ,
2343
+ );
2344
+
2345
+ $ functionName = null ;
2341
2346
if ($ node ->name instanceof String_) {
2342
2347
/** @var non-empty-string $name */
2343
2348
$ name = $ node ->name ->value ;
2344
2349
$ functionName = new Name ($ name );
2345
- } elseif ($ node ->name instanceof FuncCall) {
2350
+ } elseif ($ node ->name instanceof FuncCall && $ node -> name -> name instanceof Name ) {
2346
2351
$ functionName = $ node ->name ->name ;
2347
- } else {
2348
- return ParametersAcceptorSelector::selectFromArgs (
2349
- $ this ,
2350
- $ node ->getArgs (),
2351
- $ calledOnType ->getCallableParametersAcceptors ($ this ),
2352
- null ,
2353
- )->getReturnType ();
2354
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 ();
2355
2363
}
2356
2364
2357
- if (!$ this ->reflectionProvider ->hasFunction ($ functionName , $ this )) {
2365
+ if (!$ this ->reflectionProvider ->hasFunction ($ node -> name , $ this )) {
2358
2366
return new ErrorType ();
2359
2367
}
2360
2368
2361
- $ functionReflection = $ this ->reflectionProvider ->getFunction ($ functionName , $ this );
2369
+ $ functionReflection = $ this ->reflectionProvider ->getFunction ($ node -> name , $ this );
2362
2370
if ($ this ->nativeTypesPromoted ) {
2363
2371
return ParametersAcceptorSelector::combineAcceptors ($ functionReflection ->getVariants ())->getNativeReturnType ();
2364
2372
}
@@ -2380,19 +2388,9 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
2380
2388
);
2381
2389
$ normalizedNode = ArgumentsNormalizer::reorderFuncArguments ($ parametersAcceptor , $ node );
2382
2390
if ($ normalizedNode !== null ) {
2383
- foreach ($ this ->dynamicReturnTypeExtensionRegistry ->getDynamicFunctionReturnTypeExtensions () as $ dynamicFunctionReturnTypeExtension ) {
2384
- if (!$ dynamicFunctionReturnTypeExtension ->isFunctionSupported ($ functionReflection )) {
2385
- continue ;
2386
- }
2387
-
2388
- $ resolvedType = $ dynamicFunctionReturnTypeExtension ->getTypeFromFunctionCall (
2389
- $ functionReflection ,
2390
- $ normalizedNode ,
2391
- $ this ,
2392
- );
2393
- if ($ resolvedType !== null ) {
2394
- return $ resolvedType ;
2395
- }
2391
+ $ resolvedType = $ this ->getDynamicFunctionReturnType ($ parametersAcceptor , $ normalizedNode , $ functionReflection );
2392
+ if ($ resolvedType !== null ) {
2393
+ return $ resolvedType ;
2396
2394
}
2397
2395
}
2398
2396
@@ -2402,6 +2400,29 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
2402
2400
return new MixedType ();
2403
2401
}
2404
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
+
2405
2426
private function getNullsafeShortCircuitingType (Expr $ expr , Type $ type ): Type
2406
2427
{
2407
2428
if ($ expr instanceof Expr \NullsafePropertyFetch || $ expr instanceof Expr \NullsafeMethodCall) {
0 commit comments