Skip to content

Commit 19cd999

Browse files
committed
Fixed optimization
1 parent 2f2d6a3 commit 19cd999

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Diff for: src/Parser/VariadicMethodsVisitor.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ final class VariadicMethodsVisitor extends NodeVisitorAbstract
2929

3030
private ?string $inMethod = null;
3131

32-
/** @var array<string, array<string, true>> */
32+
/** @var array<string, array<string, bool>> */
3333
public static array $cache = [];
3434

35-
/** @var array<string, array<string, true>> */
35+
/** @var array<string, array<string, bool>> */
3636
private array $variadicMethods = [];
3737

3838
public function beforeTraverse(array $nodes): ?array
@@ -94,6 +94,10 @@ public function enterNode(Node $node): ?Node
9494
public function leaveNode(Node $node): ?Node
9595
{
9696
if ($node instanceof ClassMethod) {
97+
$lastClass = $this->classStack[count($this->classStack) - 1] ?? null;
98+
if ($lastClass !== null) {
99+
$this->variadicMethods[$lastClass][$this->inMethod] ??= false;
100+
}
97101
$this->inMethod = null;
98102
}
99103

@@ -111,12 +115,18 @@ public function leaveNode(Node $node): ?Node
111115
public function afterTraverse(array $nodes): ?array
112116
{
113117
if ($this->topNode !== null && $this->variadicMethods !== []) {
118+
$filteredMethods = [];
114119
foreach ($this->variadicMethods as $class => $methods) {
115120
foreach ($methods as $name => $variadic) {
116121
self::$cache[$class][$name] = $variadic;
122+
if (!$variadic) {
123+
continue;
124+
}
125+
126+
$filteredMethods[$class][$name] = true;
117127
}
118128
}
119-
$this->topNode->setAttribute(self::ATTRIBUTE_NAME, $this->variadicMethods);
129+
$this->topNode->setAttribute(self::ATTRIBUTE_NAME, $filteredMethods);
120130
}
121131

122132
return null;

0 commit comments

Comments
 (0)