4
4
5
5
use App \Contexts \AbstractContext ;
6
6
use App \Contexts \Argument ;
7
+ use App \Contexts \AssignmentValue ;
7
8
use App \Contexts \MethodCall ;
9
+ use Microsoft \PhpParser \Node \Expression \MemberAccessExpression ;
8
10
use Microsoft \PhpParser \Node \Expression \ScopedPropertyAccessExpression ;
11
+ use Microsoft \PhpParser \Node \Expression \Variable ;
9
12
10
13
class ScopedPropertyAccessExpressionParser extends AbstractParser
11
14
{
@@ -17,14 +20,46 @@ class ScopedPropertyAccessExpressionParser extends AbstractParser
17
20
public function parse (ScopedPropertyAccessExpression $ node )
18
21
{
19
22
$ 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 );
21
24
22
25
return $ this ->context ;
23
26
}
24
27
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
+ if ($ node ->scopeResolutionQualifier instanceof MemberAccessExpression) {
45
+ $ parser = new MemberAccessExpressionParser ;
46
+ $ context = new MethodCall ;
47
+ $ context ->parent = clone $ this ->context ;
48
+ $ parser ->context ($ context );
49
+ $ result = $ parser ->parseNode ($ node ->scopeResolutionQualifier );
50
+
51
+ return $ result ->className ?? null ;
52
+ }
53
+
54
+ return $ node ->scopeResolutionQualifier ->getText ();
55
+ }
56
+
25
57
public function initNewContext (): ?AbstractContext
26
58
{
27
- if ($ this ->context instanceof Argument) {
59
+ if (
60
+ $ this ->context instanceof Argument
61
+ || $ this ->context instanceof AssignmentValue
62
+ ) {
28
63
return new MethodCall ;
29
64
}
30
65
0 commit comments