Skip to content

Commit

Permalink
fix var search
Browse files Browse the repository at this point in the history
  • Loading branch information
patinthehat committed Jul 5, 2021
1 parent 9a08f16 commit baddbeb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Searcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ protected function traverseNodes(FileSearchResults $results, array $nodes): void
{
$traverser = new NodeTraverser();

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

$traverser->traverse($nodes);
}
Expand Down
19 changes: 12 additions & 7 deletions src/Visitors/FunctionCallVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class FunctionCallVisitor extends NodeVisitorAbstract

protected $functionNames = [];

public function __construct(FileSearchResults $results, array $functionNames)
protected $variableNames = [];

public function __construct(FileSearchResults $results, array $functionNames, array $variableNames)
{
$this->results = $results;
$this->functionNames = $functionNames;
$this->variableNames = $variableNames;
}

public function enterNode(Node $node)
Expand Down Expand Up @@ -56,13 +59,15 @@ public function enterNode(Node $node)
}

if ($node instanceof Node\Expr\Variable) {
$location = FunctionCallLocation::create(
$node->name,
$node->getStartLine(),
$node->getEndLine()
);
if (in_array($node->name, $this->variableNames, true)) {
$location = FunctionCallLocation::create(
$node->name,
$node->getStartLine(),
$node->getEndLine()
);

$this->results->addLocation($location);
$this->results->addLocation($location);
}
}

if ($node instanceof Node\Expr\New_) {
Expand Down

0 comments on commit baddbeb

Please sign in to comment.