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