2222use PHPStan \DependencyInjection \AutowiredExtensions ;
2323use PHPStan \DependencyInjection \AutowiredParameter ;
2424use PHPStan \DependencyInjection \AutowiredService ;
25- use PHPStan \DependencyInjection \Container ;
2625use PHPStan \DependencyInjection \ExtensionsCollection ;
2726use PHPStan \Node \Expr \TypeExpr ;
2827use PHPStan \Node \InvalidateExprNode ;
@@ -94,7 +93,6 @@ final class ArgumentsHandler
9493 * @param ExtensionsCollection<StaticMethodParameterClosureTypeExtension> $staticMethodParameterClosureTypeExtensions
9594 */
9695 public function __construct (
97- private Container $ container ,
9896 private TemplateArgumentObserver $ templateArgumentObserver ,
9997 private ExpressionResultFactory $ expressionResultFactory ,
10098 private ClosureProcessor $ closureProcessor ,
@@ -119,6 +117,8 @@ public function __construct(
119117 #[AutowiredParameter(ref: '%exceptions.implicitThrows% ' )]
120118 private bool $ implicitThrows ,
121119 private AssignHandler $ assignHandler ,
120+ private ClosureTypeResolver $ closureTypeResolver ,
121+ private ClosureParameterResolver $ closureParameterResolver ,
122122 )
123123 {
124124 }
@@ -233,7 +233,7 @@ public function processArgs(
233233 $ originalArgForGather = $ arg ->getAttribute (ArgumentsNormalizer::ORIGINAL_ARG_ATTRIBUTE ) ?? $ arg ;
234234 $ gatheredArgTypeByIndex [$ i ] = $ typeDrivenAcceptorSelection
235235 ? $ this ->gatherClosureArgType ($ parametersAcceptors , $ i , $ arg ->value , $ scope )
236- : $ this ->container -> getByType (ClosureTypeResolver::class) ->getClosureType ($ scope , $ arg ->value , true , $ storage );
236+ : $ this ->closureTypeResolver ->getClosureType ($ scope , $ arg ->value , true , $ storage );
237237 $ this ->addGatheredArgType ($ gatheredTypes , $ gatheredUnpack , $ gatheredHasName , $ originalArgForGather , $ i , $ gatheredArgTypeByIndex [$ i ]);
238238 }
239239
@@ -362,7 +362,6 @@ public function processArgs(
362362 // a miss means "walk it", not "price it silently": pricing skips
363363 // the body walk and never fires the closure's node callbacks
364364 if ($ storedClosureArgResult === null && $ nodeScopeResolver ->isReturningStoredExpressionResults ()) {
365- $ closureTypeResolver = $ this ->container ->getByType (ClosureTypeResolver::class);
366365 $ storedClosureArgResult = $ this ->expressionResultFactory ->create (
367366 $ scopeToPass ,
368367 beforeScope: $ scopeToPass ,
@@ -371,8 +370,8 @@ public function processArgs(
371370 isAlwaysTerminating: false ,
372371 throwPoints: [],
373372 impurePoints: [],
374- type: $ closureTypeResolver ->getClosureType ($ scopeToPass , $ arg ->value , false , $ storage ),
375- nativeType: $ closureTypeResolver ->getClosureType ($ scopeToPass ->doNotTreatPhpDocTypesAsCertain (), $ arg ->value , false , $ storage ),
373+ type: $ this -> closureTypeResolver ->getClosureType ($ scopeToPass , $ arg ->value , false , $ storage ),
374+ nativeType: $ this -> closureTypeResolver ->getClosureType ($ scopeToPass ->doNotTreatPhpDocTypesAsCertain (), $ arg ->value , false , $ storage ),
376375 typeCallback: null ,
377376 specifyTypesCallback: SpecifiedTypes ::emptySpecifyCallback (),
378377 );
@@ -418,7 +417,6 @@ public function processArgs(
418417 $ impurePoints = array_merge ($ impurePoints , $ closureResult ->getImpurePoints ());
419418 }
420419
421- $ closureTypeResolver = $ this ->container ->getByType (ClosureTypeResolver::class);
422420 $ storedClosureResult = $ this ->expressionResultFactory ->create (
423421 $ closureResult ->getScope (),
424422 $ scopeToPass ,
@@ -428,7 +426,7 @@ public function processArgs(
428426 isAlwaysTerminating: false ,
429427 throwPoints: [],
430428 impurePoints: [],
431- type: $ closureTypeResolver ->buildClosureTypeForClosure (
429+ type: $ this -> closureTypeResolver ->buildClosureTypeForClosure (
432430 $ scopeToPass ,
433431 $ arg ->value ,
434432 $ closureResult ->getGatheredReturnStatements (),
@@ -442,7 +440,7 @@ public function processArgs(
442440 ),
443441 // the native flavour reads the stored native types off the same
444442 // single body walk - no second walk on the promoted scope
445- nativeType: $ closureTypeResolver ->buildClosureTypeForClosure (
443+ nativeType: $ this -> closureTypeResolver ->buildClosureTypeForClosure (
446444 $ scopeToPass ,
447445 $ arg ->value ,
448446 $ closureResult ->getGatheredReturnStatements (),
@@ -512,7 +510,6 @@ public function processArgs(
512510 // consume mode alone (the nullsafe call's plain-twin walk) is the
513511 // first and only walk of the argument - a miss means walk it
514512 if ($ storedClosureArgResult === null && $ nodeScopeResolver ->isReturningStoredExpressionResults ()) {
515- $ closureTypeResolver = $ this ->container ->getByType (ClosureTypeResolver::class);
516513 $ storedClosureArgResult = $ this ->expressionResultFactory ->create (
517514 $ scopeToPass ,
518515 beforeScope: $ scopeToPass ,
@@ -521,8 +518,8 @@ public function processArgs(
521518 isAlwaysTerminating: false ,
522519 throwPoints: [],
523520 impurePoints: [],
524- type: $ closureTypeResolver ->getClosureType ($ scopeToPass , $ arg ->value , false , $ storage ),
525- nativeType: $ closureTypeResolver ->getClosureType ($ scopeToPass ->doNotTreatPhpDocTypesAsCertain (), $ arg ->value , false , $ storage ),
521+ type: $ this -> closureTypeResolver ->getClosureType ($ scopeToPass , $ arg ->value , false , $ storage ),
522+ nativeType: $ this -> closureTypeResolver ->getClosureType ($ scopeToPass ->doNotTreatPhpDocTypesAsCertain (), $ arg ->value , false , $ storage ),
526523 typeCallback: null ,
527524 specifyTypesCallback: SpecifiedTypes ::emptySpecifyCallback (),
528525 );
@@ -566,13 +563,12 @@ public function processArgs(
566563 $ throwPoints = array_merge ($ throwPoints , array_map (static fn (InternalThrowPoint $ throwPoint ) => $ throwPoint ->isExplicit () ? InternalThrowPoint ::createExplicit ($ scope , $ throwPoint ->getType (), $ arg ->value , $ throwPoint ->canContainAnyThrowable ()) : InternalThrowPoint ::createImplicit ($ scope , $ arg ->value ), $ arrowFunctionExprResult ->getThrowPoints ()));
567564 $ impurePoints = array_merge ($ impurePoints , $ arrowFunctionExprResult ->getImpurePoints ());
568565 }
569- $ arrowFunctionClosureTypeResolver = $ this ->container ->getByType (ClosureTypeResolver::class);
570566 $ arrowFunctionScope = $ arrowFunctionResult ->getArrowFunctionScope ();
571567 // both flavours are built from the single body walk (see
572568 // ArrowFunctionHandler); the built type also answers the
573569 // invalidate-expressions read below without re-walking the
574570 // still-unstored node through Scope::getType()
575- $ arrowFunctionType = $ arrowFunctionClosureTypeResolver ->buildClosureTypeForArrowFunction (
571+ $ arrowFunctionType = $ this -> closureTypeResolver ->buildClosureTypeForArrowFunction (
576572 $ scopeToPass ,
577573 $ arg ->value ,
578574 $ arrowFunctionScope ,
@@ -592,7 +588,7 @@ public function processArgs(
592588 throwPoints: $ arrowFunctionExprResult ->getThrowPoints (),
593589 impurePoints: $ arrowFunctionExprResult ->getImpurePoints (),
594590 type: $ arrowFunctionType ,
595- nativeType: $ arrowFunctionClosureTypeResolver ->buildClosureTypeForArrowFunction (
591+ nativeType: $ this -> closureTypeResolver ->buildClosureTypeForArrowFunction (
596592 $ scopeToPass ,
597593 $ arg ->value ,
598594 $ arrowFunctionScope ,
@@ -932,7 +928,7 @@ private function gatherClosureArgType(array $parametersAcceptors, int $i, Expr $
932928 $ scope = $ scope ->pushInFunctionCall (null , $ rawParameter , false );
933929 }
934930
935- return $ this ->container -> getByType (ClosureParameterResolver::class) ->resolveCallableTypeForScope ($ closureExpr , $ scope );
931+ return $ this ->closureParameterResolver ->resolveCallableTypeForScope ($ closureExpr , $ scope );
936932 }
937933
938934 /**
0 commit comments