1010use PHPStan \ShouldNotHappenException ;
1111use PHPStan \Type \Accessory \AccessoryArrayListType ;
1212use PHPStan \Type \ArrayType ;
13+ use PHPStan \Type \Constant \ConstantArrayType ;
1314use PHPStan \Type \Constant \ConstantIntegerType ;
1415use PHPStan \Type \Doctrine \ObjectMetadataResolver ;
1516use PHPStan \Type \DynamicMethodReturnTypeExtension ;
@@ -208,22 +209,19 @@ static function (Type $type, callable $traverse) use ($objectManager): Type {
208209
209210 private function getScalarHydratedReturnType (Type $ queryResultType ): Type
210211 {
211- if (!$ queryResultType-> isArray ()-> yes () ) {
212+ if (!$ queryResultType instanceof ArrayType ) {
212213 return new ArrayType (new MixedType (), new MixedType ());
213214 }
214215
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 ();
217219
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 ;
224222 }
225223
226- return $ queryResultType ;
224+ return new ArrayType ( new MixedType (), new MixedType ()) ;
227225 }
228226
229227 private function getSimpleObjectHydratedReturnType (Type $ queryResultType ): Type
@@ -238,41 +236,31 @@ private function getSimpleObjectHydratedReturnType(Type $queryResultType): Type
238236 private function getSingleScalarHydratedReturnType (Type $ queryResultType ): Type
239237 {
240238 $ queryResultType = $ this ->getScalarHydratedReturnType ($ queryResultType );
241- if (!$ queryResultType-> isConstantArray ()-> yes () ) {
239+ if (!$ queryResultType instanceof ConstantArrayType ) {
242240 return new MixedType ();
243241 }
244242
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 ();
253246 }
254247
255- return TypeCombinator:: union (... $ types );
248+ return $ queryResultType -> getFirstIterableValueType ( );
256249 }
257250
258251 private function getScalarColumnHydratedReturnType (Type $ queryResultType ): Type
259252 {
260253 $ queryResultType = $ this ->getScalarHydratedReturnType ($ queryResultType );
261- if (!$ queryResultType-> isConstantArray ()-> yes () ) {
254+ if (!$ queryResultType instanceof ConstantArrayType ) {
262255 return new MixedType ();
263256 }
264257
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 ();
273261 }
274262
275- return TypeCombinator:: union (... $ types );
263+ return $ queryResultType -> getFirstIterableValueType ( );
276264 }
277265
278266 private function originalReturnType (MethodReflection $ methodReflection ): Type
0 commit comments