@@ -113,7 +113,7 @@ private function getGetTypeFromMethodCall(
113
113
{
114
114
// We don't use the method's return type because this won't work properly with lowest and
115
115
// highest versions of Symfony ("mixed" for lowest, "array|bool|float|integer|string|null" for highest).
116
- $ returnType = new UnionType ([
116
+ $ defaultReturnType = new UnionType ([
117
117
new ArrayType (new MixedType (), new MixedType ()),
118
118
new BooleanType (),
119
119
new FloatType (),
@@ -122,18 +122,25 @@ private function getGetTypeFromMethodCall(
122
122
new NullType (),
123
123
]);
124
124
if (!isset ($ methodCall ->getArgs ()[0 ])) {
125
- return $ returnType ;
125
+ return $ defaultReturnType ;
126
126
}
127
127
128
- $ parameterKey = $ this ->parameterMap ::getParameterKeyFromNode ($ methodCall ->getArgs ()[0 ]->value , $ scope );
129
- if ($ parameterKey !== null ) {
128
+ $ parameterKeys = $ this ->parameterMap ::getParameterKeysFromNode ($ methodCall ->getArgs ()[0 ]->value , $ scope );
129
+ if ($ parameterKeys === []) {
130
+ return $ defaultReturnType ;
131
+ }
132
+
133
+ $ returnTypes = [];
134
+ foreach ($ parameterKeys as $ parameterKey ) {
130
135
$ parameter = $ this ->parameterMap ->getParameter ($ parameterKey );
131
- if ($ parameter ! == null ) {
132
- return $ this -> generalizeTypeFromValue ( $ scope , $ parameter -> getValue ()) ;
136
+ if ($ parameter = == null ) {
137
+ return $ defaultReturnType ;
133
138
}
139
+
140
+ $ returnTypes [] = $ this ->generalizeTypeFromValue ($ scope , $ parameter ->getValue ());
134
141
}
135
142
136
- return $ returnType ;
143
+ return TypeCombinator:: union (... $ returnTypes ) ;
137
144
}
138
145
139
146
/**
@@ -211,18 +218,31 @@ private function getHasTypeFromMethodCall(
211
218
Scope $ scope
212
219
): Type
213
220
{
214
- $ returnType = ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
221
+ $ defaultReturnType = ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
215
222
if (!isset ($ methodCall ->getArgs ()[0 ]) || !$ this ->constantHassers ) {
216
- return $ returnType ;
223
+ return $ defaultReturnType ;
217
224
}
218
225
219
- $ parameterKey = $ this ->parameterMap ::getParameterKeyFromNode ($ methodCall ->getArgs ()[0 ]->value , $ scope );
220
- if ($ parameterKey !== null ) {
226
+ $ parameterKeys = $ this ->parameterMap ::getParameterKeysFromNode ($ methodCall ->getArgs ()[0 ]->value , $ scope );
227
+ if ($ parameterKeys === []) {
228
+ return $ defaultReturnType ;
229
+ }
230
+
231
+ $ has = null ;
232
+ foreach ($ parameterKeys as $ parameterKey ) {
221
233
$ parameter = $ this ->parameterMap ->getParameter ($ parameterKey );
222
- return new ConstantBooleanType ($ parameter !== null );
234
+
235
+ if ($ has === null ) {
236
+ $ has = $ parameter !== null ;
237
+ } elseif (
238
+ ($ has === true && $ parameter === null )
239
+ || ($ has === false && $ parameter !== null )
240
+ ) {
241
+ return $ defaultReturnType ;
242
+ }
223
243
}
224
244
225
- return $ returnType ;
245
+ return new ConstantBooleanType ( $ has ) ;
226
246
}
227
247
228
248
}
0 commit comments