@@ -13,9 +13,12 @@ final class VariableParser
13
13
{
14
14
private Parser $ parser ;
15
15
16
+ private NodeFinder $ nodeFinder ;
17
+
16
18
public function __construct ()
17
19
{
18
20
$ this ->parser = (new \PhpParser \ParserFactory ())->createForNewestSupportedVersion ();
21
+ $ this ->nodeFinder = new NodeFinder ();
19
22
}
20
23
21
24
public function parse (string $ content ): ParseResult
@@ -25,9 +28,7 @@ public function parse(string $content): ParseResult
25
28
throw new ParseFailedException ();
26
29
}
27
30
28
- $ nodeFinder = new NodeFinder ();
29
-
30
- $ functionLikes = $ nodeFinder ->findInstanceOf ($ stmts , FunctionLike::class);
31
+ $ functionLikes = $ this ->nodeFinder ->findInstanceOf ($ stmts , FunctionLike::class);
31
32
32
33
$ functions = $ this ->collectParseResultPerFunctionLike ($ functionLikes );
33
34
@@ -40,14 +41,12 @@ public function parse(string $content): ParseResult
40
41
*/
41
42
private function collectParseResultPerFunctionLike (array $ functionLikes ): array
42
43
{
43
- $ nodeFinder = new NodeFinder ();
44
-
45
- return array_map (function (FunctionLike $ function ) use ($ nodeFinder ) {
44
+ return array_map (function (FunctionLike $ function ) {
46
45
$ functionIdentifier = $ function ->name ->name ?? $ function ->getType () . '@ ' . $ function ->getStartLine ();
47
46
48
47
$ func = new Func ($ functionIdentifier );
49
48
50
- $ variables = $ nodeFinder ->findInstanceOf ($ function , Variable::class);
49
+ $ variables = $ this -> nodeFinder ->findInstanceOf ($ function , Variable::class);
51
50
foreach ($ variables as $ variable ) {
52
51
$ func ->addVariable (new VarReference ($ variable ->name , $ variable ->getLine ())); // @phpstan-ignore-line
53
52
}
0 commit comments