9898use PHPStan \Type \Constant \ConstantIntegerType ;
9999use PHPStan \Type \Constant \ConstantStringType ;
100100use PHPStan \Type \ConstantTypeHelper ;
101+ use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
101102use PHPStan \Type \DynamicReturnTypeExtensionRegistry ;
102103use PHPStan \Type \ErrorType ;
103104use PHPStan \Type \ExpressionTypeResolverExtensionRegistry ;
@@ -192,6 +193,9 @@ class MutatingScope implements Scope, NodeCallbackInvoker
192193
193194 private static int $ resolveClosureTypeDepth = 0 ;
194195
196+ /** @var array<string, list<DynamicFunctionReturnTypeExtension>> */
197+ private static array $ functionReturnTypeExtensions = [];
198+
195199 /**
196200 * @param int|array{min: int, max: int}|null $configPhpVersion
197201 * @param callable(Node $node, Scope $scope): void|null $nodeCallback
@@ -2500,7 +2504,15 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
25002504
25012505 private function getDynamicFunctionReturnType (FuncCall $ normalizedNode , FunctionReflection $ functionReflection ): ?Type
25022506 {
2503- foreach ($ this ->dynamicReturnTypeExtensionRegistry ->getDynamicFunctionReturnTypeExtensions () as $ dynamicFunctionReturnTypeExtension ) {
2507+ $ functionName = $ functionReflection ->getName ();
2508+ if (isset (self ::$ functionReturnTypeExtensions [$ functionName ])) {
2509+ $ extensions = self ::$ functionReturnTypeExtensions [$ functionName ];
2510+ } else {
2511+ $ extensions = $ this ->dynamicReturnTypeExtensionRegistry ->getDynamicFunctionReturnTypeExtensions ();
2512+ }
2513+
2514+ $ supportedFunctions = [];
2515+ foreach ($ extensions as $ dynamicFunctionReturnTypeExtension ) {
25042516 if (!$ dynamicFunctionReturnTypeExtension ->isFunctionSupported ($ functionReflection )) {
25052517 continue ;
25062518 }
@@ -2510,11 +2522,15 @@ private function getDynamicFunctionReturnType(FuncCall $normalizedNode, Function
25102522 $ normalizedNode ,
25112523 $ this ,
25122524 );
2525+
2526+ $ supportedFunctions [] = $ dynamicFunctionReturnTypeExtension ;
25132527 if ($ resolvedType !== null ) {
2528+ self ::$ functionReturnTypeExtensions [$ functionName ] = $ supportedFunctions ;
25142529 return $ resolvedType ;
25152530 }
25162531 }
25172532
2533+ self ::$ functionReturnTypeExtensions [$ functionName ] = $ supportedFunctions ;
25182534 return null ;
25192535 }
25202536
0 commit comments