4
4
5
5
use mglaman \PHPStanDrupal \Drupal \DrupalServiceDefinition ;
6
6
use mglaman \PHPStanDrupal \Drupal \ServiceMap ;
7
+ use PhpParser \Node ;
8
+ use PhpParser \Node \Expr \ClassConstFetch ;
7
9
use PhpParser \Node \Expr \MethodCall ;
10
+ use PhpParser \Node \Name \FullyQualified ;
8
11
use PhpParser \Node \Scalar \String_ ;
9
12
use PhpParser \Node \VariadicPlaceholder ;
10
13
use PHPStan \Analyser \Scope ;
@@ -52,13 +55,12 @@ public function getTypeFromMethodCall(
52
55
throw new ShouldNotHappenException ();
53
56
}
54
57
$ arg1 = $ arg1 ->value ;
55
- if (!$ arg1 instanceof String_) {
56
- // @todo determine what these types are.
58
+
59
+ $ serviceId = $ this ->getServiceId ($ arg1 );
60
+ if ($ serviceId === null ) {
57
61
return $ returnType ;
58
62
}
59
63
60
- $ serviceId = $ arg1 ->value ;
61
-
62
64
if ($ methodReflection ->getName () === 'get ' ) {
63
65
$ service = $ this ->serviceMap ->getService ($ serviceId );
64
66
if ($ service instanceof DrupalServiceDefinition) {
@@ -73,4 +75,18 @@ public function getTypeFromMethodCall(
73
75
74
76
throw new ShouldNotHappenException ();
75
77
}
78
+
79
+ protected function getServiceId (Node $ arg1 ): ?string
80
+ {
81
+ if ($ arg1 instanceof String_) {
82
+ // @todo determine what these types are.
83
+ return $ arg1 ->value ;
84
+ }
85
+
86
+ if ($ arg1 instanceof ClassConstFetch && $ arg1 ->class instanceof FullyQualified) {
87
+ return (string ) $ arg1 ->class ;
88
+ }
89
+
90
+ return null ;
91
+ }
76
92
}
0 commit comments