6363final class ClosureTypeResolver implements PerFileAnalysisResettable
6464{
6565
66+ private const PHPSTAN_FREE_VARIABLE_ROOTS_ATTRIBUTE = 'phpstanFreeVariableRoots ' ;
67+
6668 private static int $ resolveClosureTypeDepth = 0 ;
6769
6870 /**
@@ -424,7 +426,7 @@ private function closureContextCacheKey(MutatingScope $scope, Node\Expr\Closure|
424426 private function freeVariableRoots (Node \Expr \Closure |ArrowFunction $ expr ): ?array
425427 {
426428 /** @var list<string>|false|null $cached */
427- $ cached = $ expr ->getAttribute (' phpstanFreeVariableRoots ' , false );
429+ $ cached = $ expr ->getAttribute (self :: PHPSTAN_FREE_VARIABLE_ROOTS_ATTRIBUTE , false );
428430 if ($ cached !== false ) {
429431 return $ cached ;
430432 }
@@ -437,7 +439,7 @@ private function freeVariableRoots(Node\Expr\Closure|ArrowFunction $expr): ?arra
437439 if ($ expr instanceof Node \Expr \Closure) {
438440 foreach ($ expr ->uses as $ use ) {
439441 if (!is_string ($ use ->var ->name )) {
440- $ expr ->setAttribute (' phpstanFreeVariableRoots ' , null );
442+ $ expr ->setAttribute (self :: PHPSTAN_FREE_VARIABLE_ROOTS_ATTRIBUTE , null );
441443 return null ;
442444 }
443445 $ roots ['$ ' . $ use ->var ->name ] = true ;
@@ -454,7 +456,7 @@ private function freeVariableRoots(Node\Expr\Closure|ArrowFunction $expr): ?arra
454456 $ finder = new NodeFinder ();
455457 foreach ($ finder ->findInstanceOf ([$ expr ->expr ], Node \Expr \Variable::class) as $ variable ) {
456458 if (!is_string ($ variable ->name )) {
457- $ expr ->setAttribute (' phpstanFreeVariableRoots ' , null );
459+ $ expr ->setAttribute (self :: PHPSTAN_FREE_VARIABLE_ROOTS_ATTRIBUTE , null );
458460 return null ;
459461 }
460462 $ name = '$ ' . $ variable ->name ;
@@ -465,14 +467,14 @@ private function freeVariableRoots(Node\Expr\Closure|ArrowFunction $expr): ?arra
465467 }
466468 foreach ($ finder ->findInstanceOf ([$ expr ->expr ], Node \Expr \FuncCall::class) as $ call ) {
467469 if ($ call ->name instanceof Node \Name && in_array ($ call ->name ->toLowerString (), ['compact ' , 'extract ' , 'get_defined_vars ' ], true )) {
468- $ expr ->setAttribute (' phpstanFreeVariableRoots ' , null );
470+ $ expr ->setAttribute (self :: PHPSTAN_FREE_VARIABLE_ROOTS_ATTRIBUTE , null );
469471 return null ;
470472 }
471473 }
472474 }
473475
474476 $ rootList = array_keys ($ roots );
475- $ expr ->setAttribute (' phpstanFreeVariableRoots ' , $ rootList );
477+ $ expr ->setAttribute (self :: PHPSTAN_FREE_VARIABLE_ROOTS_ATTRIBUTE , $ rootList );
476478
477479 return $ rootList ;
478480 }
0 commit comments