@@ -13,9 +13,12 @@ final class VariableParser
1313{
1414 private Parser $ parser ;
1515
16+ private NodeFinder $ nodeFinder ;
17+
1618 public function __construct ()
1719 {
1820 $ this ->parser = (new \PhpParser \ParserFactory ())->createForNewestSupportedVersion ();
21+ $ this ->nodeFinder = new NodeFinder ();
1922 }
2023
2124 public function parse (string $ content ): ParseResult
@@ -25,9 +28,7 @@ public function parse(string $content): ParseResult
2528 throw new ParseFailedException ();
2629 }
2730
28- $ nodeFinder = new NodeFinder ();
29-
30- $ functionLikes = $ nodeFinder ->findInstanceOf ($ stmts , FunctionLike::class);
31+ $ functionLikes = $ this ->nodeFinder ->findInstanceOf ($ stmts , FunctionLike::class);
3132
3233 $ functions = $ this ->collectParseResultPerFunctionLike ($ functionLikes );
3334
@@ -40,14 +41,12 @@ public function parse(string $content): ParseResult
4041 */
4142 private function collectParseResultPerFunctionLike (array $ functionLikes ): array
4243 {
43- $ nodeFinder = new NodeFinder ();
44-
45- return array_map (function (FunctionLike $ function ) use ($ nodeFinder ) {
44+ return array_map (function (FunctionLike $ function ) {
4645 $ functionIdentifier = $ function ->name ->name ?? $ function ->getType () . '@ ' . $ function ->getStartLine ();
4746
4847 $ func = new Func ($ functionIdentifier );
4948
50- $ variables = $ nodeFinder ->findInstanceOf ($ function , Variable::class);
49+ $ variables = $ this -> nodeFinder ->findInstanceOf ($ function , Variable::class);
5150 foreach ($ variables as $ variable ) {
5251 $ func ->addVariable (new VarReference ($ variable ->name , $ variable ->getLine ())); // @phpstan-ignore-line
5352 }
0 commit comments