55use PhpParser \Node \Expr \MethodCall ;
66use PHPStan \Analyser \Scope ;
77use PHPStan \Reflection \MethodReflection ;
8- use PHPStan \Reflection \ParametersAcceptorSelector ;
98use PHPStan \ShouldNotHappenException ;
109use PHPStan \Symfony \Configuration ;
1110use PHPStan \Symfony \ParameterMap ;
@@ -56,7 +55,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
5655 return in_array ($ methodReflection ->getName (), ['get ' , 'has ' ], true );
5756 }
5857
59- public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): Type
58+ public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): ? Type
6059 {
6160 switch ($ methodReflection ->getName ()) {
6261 case 'get ' :
@@ -71,16 +70,15 @@ private function getGetTypeFromMethodCall(
7170 MethodReflection $ methodReflection ,
7271 MethodCall $ methodCall ,
7372 Scope $ scope
74- ): Type
73+ ): ? Type
7574 {
76- $ returnType = ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
7775 if (!isset ($ methodCall ->getArgs ()[0 ])) {
78- return $ returnType ;
76+ return null ;
7977 }
8078
8179 $ parameterBag = $ this ->tryGetParameterBag ();
8280 if ($ parameterBag === null ) {
83- return $ returnType ;
81+ return null ;
8482 }
8583
8684 $ serviceId = $ this ->serviceMap ::getServiceIdFromNode ($ methodCall ->getArgs ()[0 ]->value , $ scope );
@@ -91,7 +89,7 @@ private function getGetTypeFromMethodCall(
9189 }
9290 }
9391
94- return $ returnType ;
92+ return null ;
9593 }
9694
9795 private function tryGetParameterBag (): ?ParameterBag
@@ -122,11 +120,10 @@ private function getHasTypeFromMethodCall(
122120 MethodReflection $ methodReflection ,
123121 MethodCall $ methodCall ,
124122 Scope $ scope
125- ): Type
123+ ): ? Type
126124 {
127- $ returnType = ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
128125 if (!isset ($ methodCall ->getArgs ()[0 ]) || !$ this ->constantHassers ) {
129- return $ returnType ;
126+ return null ;
130127 }
131128
132129 $ serviceId = $ this ->serviceMap ::getServiceIdFromNode ($ methodCall ->getArgs ()[0 ]->value , $ scope );
@@ -135,7 +132,7 @@ private function getHasTypeFromMethodCall(
135132 return new ConstantBooleanType ($ service !== null && $ service ->isPublic ());
136133 }
137134
138- return $ returnType ;
135+ return null ;
139136 }
140137
141138 private function determineServiceClass (ParameterBag $ parameterBag , ServiceDefinition $ service ): ?string
0 commit comments