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 Error ;
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,36 @@ 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
+ return $ node ->scopeResolutionQualifier ->getText ();
45
+ }
46
+
25
47
public function initNewContext (): ?AbstractContext
26
48
{
27
- if ($ this ->context instanceof Argument) {
49
+ if (
50
+ $ this ->context instanceof Argument
51
+ || $ this ->context instanceof AssignmentValue
52
+ ) {
28
53
return new MethodCall ;
29
54
}
30
55
0 commit comments