5
5
use PhpParser \Node \Expr \MethodCall ;
6
6
use PHPStan \Analyser \Scope ;
7
7
use PHPStan \Reflection \MethodReflection ;
8
- use PHPStan \Reflection \ParametersAcceptorSelector ;
9
8
use PHPStan \ShouldNotHappenException ;
10
9
use PHPStan \Symfony \Configuration ;
11
10
use PHPStan \Symfony \ParameterMap ;
@@ -56,7 +55,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
56
55
return in_array ($ methodReflection ->getName (), ['get ' , 'has ' ], true );
57
56
}
58
57
59
- public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): Type
58
+ public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): ? Type
60
59
{
61
60
switch ($ methodReflection ->getName ()) {
62
61
case 'get ' :
@@ -71,16 +70,15 @@ private function getGetTypeFromMethodCall(
71
70
MethodReflection $ methodReflection ,
72
71
MethodCall $ methodCall ,
73
72
Scope $ scope
74
- ): Type
73
+ ): ? Type
75
74
{
76
- $ returnType = ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
77
75
if (!isset ($ methodCall ->getArgs ()[0 ])) {
78
- return $ returnType ;
76
+ return null ;
79
77
}
80
78
81
79
$ parameterBag = $ this ->tryGetParameterBag ();
82
80
if ($ parameterBag === null ) {
83
- return $ returnType ;
81
+ return null ;
84
82
}
85
83
86
84
$ serviceId = $ this ->serviceMap ::getServiceIdFromNode ($ methodCall ->getArgs ()[0 ]->value , $ scope );
@@ -91,7 +89,7 @@ private function getGetTypeFromMethodCall(
91
89
}
92
90
}
93
91
94
- return $ returnType ;
92
+ return null ;
95
93
}
96
94
97
95
private function tryGetParameterBag (): ?ParameterBag
@@ -122,11 +120,10 @@ private function getHasTypeFromMethodCall(
122
120
MethodReflection $ methodReflection ,
123
121
MethodCall $ methodCall ,
124
122
Scope $ scope
125
- ): Type
123
+ ): ? Type
126
124
{
127
- $ returnType = ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
128
125
if (!isset ($ methodCall ->getArgs ()[0 ]) || !$ this ->constantHassers ) {
129
- return $ returnType ;
126
+ return null ;
130
127
}
131
128
132
129
$ serviceId = $ this ->serviceMap ::getServiceIdFromNode ($ methodCall ->getArgs ()[0 ]->value , $ scope );
@@ -135,7 +132,7 @@ private function getHasTypeFromMethodCall(
135
132
return new ConstantBooleanType ($ service !== null && $ service ->isPublic ());
136
133
}
137
134
138
- return $ returnType ;
135
+ return null ;
139
136
}
140
137
141
138
private function determineServiceClass (ParameterBag $ parameterBag , ServiceDefinition $ service ): ?string
0 commit comments