Skip to content

Commit a70ad03

Browse files
committed
refactor: 冗長な処理を省く
1 parent c3e3b65 commit a70ad03

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/Parse/VariableParser.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)