Skip to content

Commit baddbeb

Browse files
committed
fix var search
1 parent 9a08f16 commit baddbeb

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Searcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ protected function traverseNodes(FileSearchResults $results, array $nodes): void
267267
{
268268
$traverser = new NodeTraverser();
269269

270-
$traverser->addVisitor(new FunctionCallVisitor($results, $this->functions));
270+
$traverser->addVisitor(new FunctionCallVisitor($results, $this->functions, $this->variables));
271271

272272
$traverser->traverse($nodes);
273273
}

src/Visitors/FunctionCallVisitor.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ class FunctionCallVisitor extends NodeVisitorAbstract
1515

1616
protected $functionNames = [];
1717

18-
public function __construct(FileSearchResults $results, array $functionNames)
18+
protected $variableNames = [];
19+
20+
public function __construct(FileSearchResults $results, array $functionNames, array $variableNames)
1921
{
2022
$this->results = $results;
2123
$this->functionNames = $functionNames;
24+
$this->variableNames = $variableNames;
2225
}
2326

2427
public function enterNode(Node $node)
@@ -56,13 +59,15 @@ public function enterNode(Node $node)
5659
}
5760

5861
if ($node instanceof Node\Expr\Variable) {
59-
$location = FunctionCallLocation::create(
60-
$node->name,
61-
$node->getStartLine(),
62-
$node->getEndLine()
63-
);
62+
if (in_array($node->name, $this->variableNames, true)) {
63+
$location = FunctionCallLocation::create(
64+
$node->name,
65+
$node->getStartLine(),
66+
$node->getEndLine()
67+
);
6468

65-
$this->results->addLocation($location);
69+
$this->results->addLocation($location);
70+
}
6671
}
6772

6873
if ($node instanceof Node\Expr\New_) {

0 commit comments

Comments
 (0)