1010use PHPStan \ShouldNotHappenException ;
1111use PHPStan \Type \Accessory \AccessoryArrayListType ;
1212use PHPStan \Type \ArrayType ;
13- use PHPStan \Type \Constant \ConstantArrayType ;
1413use PHPStan \Type \Constant \ConstantIntegerType ;
1514use PHPStan \Type \Doctrine \ObjectMetadataResolver ;
1615use PHPStan \Type \DynamicMethodReturnTypeExtension ;
@@ -209,19 +208,22 @@ static function (Type $type, callable $traverse) use ($objectManager): Type {
209208
210209 private function getScalarHydratedReturnType (Type $ queryResultType ): Type
211210 {
212- if (!$ queryResultType instanceof ArrayType ) {
211+ if (!$ queryResultType-> isArray ()-> yes () ) {
213212 return new ArrayType (new MixedType (), new MixedType ());
214213 }
215214
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 ();
219217
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+ }
222224 }
223225
224- return new ArrayType ( new MixedType (), new MixedType ()) ;
226+ return $ queryResultType ;
225227 }
226228
227229 private function getSimpleObjectHydratedReturnType (Type $ queryResultType ): Type
@@ -236,31 +238,41 @@ private function getSimpleObjectHydratedReturnType(Type $queryResultType): Type
236238 private function getSingleScalarHydratedReturnType (Type $ queryResultType ): Type
237239 {
238240 $ queryResultType = $ this ->getScalarHydratedReturnType ($ queryResultType );
239- if (!$ queryResultType instanceof ConstantArrayType ) {
241+ if (!$ queryResultType-> isConstantArray ()-> yes () ) {
240242 return new MixedType ();
241243 }
242244
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 ();
246253 }
247254
248- return $ queryResultType -> getFirstIterableValueType ( );
255+ return TypeCombinator:: union (... $ types );
249256 }
250257
251258 private function getScalarColumnHydratedReturnType (Type $ queryResultType ): Type
252259 {
253260 $ queryResultType = $ this ->getScalarHydratedReturnType ($ queryResultType );
254- if (!$ queryResultType instanceof ConstantArrayType ) {
261+ if (!$ queryResultType-> isConstantArray ()-> yes () ) {
255262 return new MixedType ();
256263 }
257264
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 ();
261273 }
262274
263- return $ queryResultType -> getFirstIterableValueType ( );
275+ return TypeCombinator:: union (... $ types );
264276 }
265277
266278 private function originalReturnType (MethodReflection $ methodReflection ): Type
0 commit comments