Skip to content

Commit 3a20bca

Browse files
committed
various bug fixes
1 parent 37a57c0 commit 3a20bca

4 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/Results/Nodes/VariableNode.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Permafrost\PhpCodeSearch\Code\GenericCodeLocation;
66
use Permafrost\PhpCodeSearch\Results\Nodes\Traits\HasLocation;
7+
use Permafrost\PhpCodeSearch\Support\NameResolver;
78
use PhpParser\Node;
89

910
class VariableNode implements ResultNode
@@ -15,11 +16,14 @@ class VariableNode implements ResultNode
1516

1617
public function __construct(Node $node)
1718
{
18-
if ($node instanceof Node\Expr\New_) {
19-
$this->name = $node->class->toString();
20-
} else {
21-
$this->name = $node->name;
22-
}
19+
20+
$this->name = NameResolver::resolve($node);
21+
22+
// if ($node instanceof Node\Expr\New_) {
23+
// $this->name = $node->class->toString();
24+
// } else {
25+
// $this->name = $node->name;
26+
// }
2327

2428
$this->location = GenericCodeLocation::createFromNode($node);
2529
}

src/Visitors/AssignmentVisitor.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Permafrost\PhpCodeSearch\Results\FileSearchResults;
77
use Permafrost\PhpCodeSearch\Results\Nodes\AssignmentNode;
88
use Permafrost\PhpCodeSearch\Support\Arr;
9+
use Permafrost\PhpCodeSearch\Support\NameResolver;
910
use PhpParser\Node;
1011
use PhpParser\NodeVisitorAbstract;
1112

@@ -26,7 +27,13 @@ public function enterNode(Node $node)
2627
{
2728
if ($node instanceof Node\Expr\Assign) {
2829
if (! $node->var instanceof Node\Expr\ArrayDimFetch) {
29-
if (Arr::matches($node->var->name, $this->names, true)) {
30+
$name = NameResolver::resolve($node->var);
31+
32+
if (is_array($name)) {
33+
$name = array_pop($name);
34+
}
35+
36+
if (Arr::matches($name ?? '', $this->names, true)) {
3037
$resultNode = AssignmentNode::create($node);
3138

3239
$this->results->add($resultNode, $resultNode->location());

src/Visitors/FunctionCallVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Permafrost\PhpCodeSearch\Results\FileSearchResults;
66
use Permafrost\PhpCodeSearch\Results\Nodes\FunctionCallNode;
77
use Permafrost\PhpCodeSearch\Support\Arr;
8+
use Permafrost\PhpCodeSearch\Support\NameResolver;
89
use PhpParser\Node;
910
use PhpParser\Node\Expr\FuncCall;
1011
use PhpParser\NodeVisitorAbstract;
@@ -25,7 +26,7 @@ public function __construct(FileSearchResults $results, array $names)
2526
public function enterNode(Node $node)
2627
{
2728
if ($node instanceof FuncCall) {
28-
if (Arr::matches($node->name, $this->names, true)) {
29+
if (Arr::matches(NameResolver::resolve($node), $this->names, true)) {
2930
$resultNode = FunctionCallNode::create($node);
3031

3132
$this->results->add($resultNode, $resultNode->location());

src/Visitors/NewClassVisitor.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Permafrost\PhpCodeSearch\Results\FileSearchResults;
66
use Permafrost\PhpCodeSearch\Results\Nodes\VariableNode;
7+
use Permafrost\PhpCodeSearch\Support\Arr;
8+
use Permafrost\PhpCodeSearch\Support\NameResolver;
79
use PhpParser\Node;
810
use PhpParser\NodeVisitorAbstract;
911

@@ -23,9 +25,11 @@ public function __construct(FileSearchResults $results, array $names)
2325
public function enterNode(Node $node)
2426
{
2527
if ($node instanceof Node\Expr\New_) {
26-
$resultNode = VariableNode::create($node);
28+
if (Arr::matches(NameResolver::resolve($node->class), $this->names, true)) {
29+
$resultNode = VariableNode::create($node);
2730

28-
$this->results->add($resultNode, $resultNode->location());
31+
$this->results->add($resultNode, $resultNode->location());
32+
}
2933
}
3034
}
3135
}

0 commit comments

Comments
 (0)