Skip to content

Commit fb2dcf9

Browse files
committed
better resolution of class name
1 parent fd03193 commit fb2dcf9

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

app/Parsers/ScopedPropertyAccessExpressionParser.php

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

55
use App\Contexts\AbstractContext;
66
use App\Contexts\Argument;
7+
use App\Contexts\AssignmentValue;
78
use App\Contexts\MethodCall;
9+
use Error;
810
use Microsoft\PhpParser\Node\Expression\ScopedPropertyAccessExpression;
11+
use Microsoft\PhpParser\Node\Expression\Variable;
912

1013
class ScopedPropertyAccessExpressionParser extends AbstractParser
1114
{
@@ -17,14 +20,36 @@ class ScopedPropertyAccessExpressionParser extends AbstractParser
1720
public function parse(ScopedPropertyAccessExpression $node)
1821
{
1922
$this->context->methodName = $node->memberName->getFullText($node->getRoot()->getFullText());
20-
$this->context->className = (string) ($node->scopeResolutionQualifier?->getResolvedName() ?? $node->scopeResolutionQualifier?->getText());
23+
$this->context->className = $this->resolveClassName($node);
2124

2225
return $this->context;
2326
}
2427

28+
protected function resolveClassName(ScopedPropertyAccessExpression $node)
29+
{
30+
if (method_exists($node->scopeResolutionQualifier, 'getResolvedName')) {
31+
return (string) $node->scopeResolutionQualifier->getResolvedName();
32+
}
33+
34+
if ($node->scopeResolutionQualifier instanceof Variable) {
35+
$result = $this->context->searchForVar($node->scopeResolutionQualifier->getName());
36+
37+
if ($result instanceof AssignmentValue) {
38+
return $result->getValue()['name'] ?? null;
39+
}
40+
41+
return $result;
42+
}
43+
44+
return $node->scopeResolutionQualifier->getText();
45+
}
46+
2547
public function initNewContext(): ?AbstractContext
2648
{
27-
if ($this->context instanceof Argument) {
49+
if (
50+
$this->context instanceof Argument
51+
|| $this->context instanceof AssignmentValue
52+
) {
2853
return new MethodCall;
2954
}
3055

0 commit comments

Comments
 (0)