10
10
use PHPStan \ShouldNotHappenException ;
11
11
use PHPStan \Type \Accessory \AccessoryArrayListType ;
12
12
use PHPStan \Type \ArrayType ;
13
- use PHPStan \Type \Constant \ConstantArrayType ;
14
13
use PHPStan \Type \Constant \ConstantIntegerType ;
15
14
use PHPStan \Type \Doctrine \ObjectMetadataResolver ;
16
15
use PHPStan \Type \DynamicMethodReturnTypeExtension ;
@@ -209,19 +208,22 @@ static function (Type $type, callable $traverse) use ($objectManager): Type {
209
208
210
209
private function getScalarHydratedReturnType (Type $ queryResultType ): Type
211
210
{
212
- if (!$ queryResultType instanceof ArrayType ) {
211
+ if (!$ queryResultType-> isArray ()-> yes () ) {
213
212
return new ArrayType (new MixedType (), new MixedType ());
214
213
}
215
214
216
- $ itemType = $ queryResultType ->getItemType ();
217
- $ hasNoObject = (new ObjectWithoutClassType ())->isSuperTypeOf ($ itemType )->no ();
218
- $ hasNoArray = $ itemType ->isArray ()->no ();
215
+ foreach ($ queryResultType ->getArrays () as $ arrayType ) {
216
+ $ itemType = $ arrayType ->getItemType ();
219
217
220
- if ($ hasNoArray && $ hasNoObject ) {
221
- return $ queryResultType ;
218
+ if (
219
+ !(new ObjectWithoutClassType ())->isSuperTypeOf ($ itemType )->no ()
220
+ || !$ itemType ->isArray ()->no ()
221
+ ) {
222
+ return new ArrayType (new MixedType (), new MixedType ());
223
+ }
222
224
}
223
225
224
- return new ArrayType ( new MixedType (), new MixedType ()) ;
226
+ return $ queryResultType ;
225
227
}
226
228
227
229
private function getSimpleObjectHydratedReturnType (Type $ queryResultType ): Type
@@ -236,31 +238,41 @@ private function getSimpleObjectHydratedReturnType(Type $queryResultType): Type
236
238
private function getSingleScalarHydratedReturnType (Type $ queryResultType ): Type
237
239
{
238
240
$ queryResultType = $ this ->getScalarHydratedReturnType ($ queryResultType );
239
- if (!$ queryResultType instanceof ConstantArrayType ) {
241
+ if (!$ queryResultType-> isConstantArray ()-> yes () ) {
240
242
return new MixedType ();
241
243
}
242
244
243
- $ values = $ queryResultType ->getValueTypes ();
244
- if (count ($ values ) !== 1 ) {
245
- return new MixedType ();
245
+ $ types = [];
246
+ foreach ($ queryResultType ->getConstantArrays () as $ constantArrayType ) {
247
+ $ values = $ constantArrayType ->getValueTypes ();
248
+ if (count ($ values ) !== 1 ) {
249
+ return new MixedType ();
250
+ }
251
+
252
+ $ types [] = $ constantArrayType ->getFirstIterableValueType ();
246
253
}
247
254
248
- return $ queryResultType -> getFirstIterableValueType ( );
255
+ return TypeCombinator:: union (... $ types );
249
256
}
250
257
251
258
private function getScalarColumnHydratedReturnType (Type $ queryResultType ): Type
252
259
{
253
260
$ queryResultType = $ this ->getScalarHydratedReturnType ($ queryResultType );
254
- if (!$ queryResultType instanceof ConstantArrayType ) {
261
+ if (!$ queryResultType-> isConstantArray ()-> yes () ) {
255
262
return new MixedType ();
256
263
}
257
264
258
- $ values = $ queryResultType ->getValueTypes ();
259
- if (count ($ values ) !== 1 ) {
260
- return new MixedType ();
265
+ $ types = [];
266
+ foreach ($ queryResultType ->getConstantArrays () as $ constantArrayType ) {
267
+ $ values = $ constantArrayType ->getValueTypes ();
268
+ if (count ($ values ) !== 1 ) {
269
+ return new MixedType ();
270
+ }
271
+
272
+ $ types [] = $ constantArrayType ->getFirstIterableValueType ();
261
273
}
262
274
263
- return $ queryResultType -> getFirstIterableValueType ( );
275
+ return TypeCombinator:: union (... $ types );
264
276
}
265
277
266
278
private function originalReturnType (MethodReflection $ methodReflection ): Type
0 commit comments