Skip to content

Commit 2060722

Browse files
committed
refactor: メソッドに切り出す
1 parent a11fe43 commit 2060722

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Parse/VariableParser.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,29 @@ public function parse(string $content): ParseResult
2929

3030
$functionLikes = $nodeFinder->findInstanceOf($stmts, FunctionLike::class);
3131

32-
$functions = array_map(function (FunctionLike $function) use ($nodeFinder) {
32+
$functions = $this->collectParseResultPerFunctionLike($functionLikes);
33+
34+
return new ParseResult($functions);
35+
}
36+
37+
/**
38+
* @param list<FunctionLike> $functionLikes
39+
* @return list<Func>
40+
*/
41+
private function collectParseResultPerFunctionLike(array $functionLikes): array
42+
{
43+
$nodeFinder = new NodeFinder();
44+
45+
return array_map(function (FunctionLike $function) use ($nodeFinder) {
3346
$functionIdentifier = $function->name->name ?? $function->getType() . '@' . $function->getStartLine();
3447

3548
$func = new Func($functionIdentifier);
49+
3650
$variables = $nodeFinder->findInstanceOf($function, Variable::class);
3751
foreach ($variables as $variable) {
3852
$func->addVariable(new VarReference($variable->name, $variable->getLine()));
3953
}
4054
return $func;
4155
}, $functionLikes);
42-
43-
return new ParseResult($functions);
4456
}
4557
}

0 commit comments

Comments
 (0)