175175use function array_slice ;
176176use function array_values ;
177177use function count ;
178- use function get_class ;
179178use function in_array ;
180179use function is_array ;
181180use function is_int ;
@@ -198,19 +197,6 @@ class NodeScopeResolver
198197 /** @var array<string, true> filePath(string) => bool(true) */
199198 private array $ analysedFiles = [];
200199
201- /**
202- * Memoizes which ExprHandler handles each Expr class so processExprNode() does not
203- * re-scan every tagged handler on each call. Keyed by Expr class-string; false means
204- * no handler matched (default handling).
205- *
206- * Call-likes (Expr\CallLike) are never memoized: their handlers select on
207- * isFirstClassCallable(), which the Expr class alone does not determine. Every other
208- * handler's supports() is a pure instanceof check, so the class fully determines it.
209- *
210- * @var array<class-string<Expr>, ExprHandler<Expr>|false>
211- */
212- private array $ exprHandlersByClass = [];
213-
214200 /** @var array<string, true> */
215201 private array $ earlyTerminatingMethodNames ;
216202
@@ -2805,7 +2791,7 @@ public function processExprNode(
28052791
28062792 $ this ->callNodeCallbackWithExpression ($ nodeCallback , $ expr , $ scope , $ storage , $ context );
28072793
2808- $ exprHandler = $ this ->resolveExprHandler ( $ expr );
2794+ $ exprHandler = ExprHandlerRegistry :: resolve ( $ expr , $ this ->container );
28092795 if ($ exprHandler !== null ) {
28102796 return $ exprHandler ->processExpr ($ this , $ stmt , $ expr , $ scope , $ storage , $ nodeCallback , $ context );
28112797 }
@@ -2826,40 +2812,6 @@ public function processExprNode(
28262812 );
28272813 }
28282814
2829- /**
2830- * Resolves the ExprHandler for the given expression, memoizing the result by Expr class.
2831- *
2832- * @return ExprHandler<Expr>|null
2833- */
2834- private function resolveExprHandler (Expr $ expr ): ?ExprHandler
2835- {
2836- // Call-likes are excluded from the cache: their handlers select on
2837- // isFirstClassCallable(), so the Expr class does not uniquely determine the handler.
2838- if (!$ expr instanceof Expr \CallLike) {
2839- $ cached = $ this ->exprHandlersByClass [get_class ($ expr )] ?? null ;
2840- if ($ cached !== null ) {
2841- return $ cached === false ? null : $ cached ;
2842- }
2843- }
2844-
2845- $ matchedHandler = null ;
2846- /** @var ExprHandler<Expr> $exprHandler */
2847- foreach ($ this ->container ->getServicesByTag (ExprHandler::EXTENSION_TAG ) as $ exprHandler ) {
2848- if (!$ exprHandler ->supports ($ expr )) {
2849- continue ;
2850- }
2851-
2852- $ matchedHandler = $ exprHandler ;
2853- break ;
2854- }
2855-
2856- if (!$ expr instanceof Expr \CallLike) {
2857- $ this ->exprHandlersByClass [get_class ($ expr )] = $ matchedHandler ?? false ;
2858- }
2859-
2860- return $ matchedHandler ;
2861- }
2862-
28632815 /**
28642816 * @param 'get'|'set' $hookName
28652817 * @return InternalThrowPoint[]
0 commit comments