@@ -42,9 +42,6 @@ final class QueryResultDynamicReturnTypeExtension implements DynamicMethodReturn
4242
4343 private const METHOD_HYDRATION_MODE = [
4444 'getArrayResult ' => AbstractQuery::HYDRATE_ARRAY ,
45- 'getScalarResult ' => AbstractQuery::HYDRATE_SCALAR ,
46- 'getSingleColumnResult ' => AbstractQuery::HYDRATE_SCALAR_COLUMN ,
47- 'getSingleScalarResult ' => AbstractQuery::HYDRATE_SINGLE_SCALAR ,
4845 ];
4946
5047 /** @var ObjectMetadataResolver */
@@ -130,26 +127,15 @@ private function getMethodReturnTypeForHydrationMode(
130127 return null ;
131128 }
132129
133- $ singleResult = false ;
134130 switch ($ hydrationMode ->getValue ()) {
135131 case AbstractQuery::HYDRATE_OBJECT :
136132 break ;
137133 case AbstractQuery::HYDRATE_ARRAY :
138134 $ queryResultType = $ this ->getArrayHydratedReturnType ($ queryResultType );
139135 break ;
140- case AbstractQuery::HYDRATE_SCALAR :
141- $ queryResultType = $ this ->getScalarHydratedReturnType ($ queryResultType );
142- break ;
143- case AbstractQuery::HYDRATE_SINGLE_SCALAR :
144- $ singleResult = true ;
145- $ queryResultType = $ this ->getSingleScalarHydratedReturnType ($ queryResultType );
146- break ;
147136 case AbstractQuery::HYDRATE_SIMPLEOBJECT :
148137 $ queryResultType = $ this ->getSimpleObjectHydratedReturnType ($ queryResultType );
149138 break ;
150- case AbstractQuery::HYDRATE_SCALAR_COLUMN :
151- $ queryResultType = $ this ->getScalarColumnHydratedReturnType ($ queryResultType );
152- break ;
153139 default :
154140 return null ;
155141 }
@@ -174,10 +160,6 @@ private function getMethodReturnTypeForHydrationMode(
174160 $ queryResultType
175161 );
176162 default :
177- if ($ singleResult ) {
178- return $ queryResultType ;
179- }
180-
181163 if ($ queryKeyType ->isNull ()->yes ()) {
182164 return AccessoryArrayListType::intersectWith (new ArrayType (
183165 new IntegerType (),
@@ -235,36 +217,6 @@ static function (Type $type, callable $traverse) use ($objectManager, &$mixedFou
235217 return $ mixedFound ? null : $ queryResultType ;
236218 }
237219
238- /**
239- * When we're scalar-hydrating object, we're not sure of the shape of the array.
240- * We could return `new ArrayTyp(new MixedType(), new MixedType())`
241- * but the lack of precision in the array keys/values would give false positive.
242- *
243- * @see https://github.com/phpstan/phpstan-doctrine/pull/453#issuecomment-1895415544
244- */
245- private function getScalarHydratedReturnType (Type $ queryResultType ): ?Type
246- {
247- if (!$ queryResultType ->isArray ()->yes ()) {
248- return null ;
249- }
250-
251- foreach ($ queryResultType ->getArrays () as $ arrayType ) {
252- $ itemType = $ arrayType ->getItemType ();
253-
254- if (
255- !(new ObjectWithoutClassType ())->isSuperTypeOf ($ itemType )->no ()
256- || !$ itemType ->isArray ()->no ()
257- ) {
258- // We could return `new ArrayTyp(new MixedType(), new MixedType())`
259- // but the lack of precision in the array keys/values would give false positive
260- // @see https://github.com/phpstan/phpstan-doctrine/pull/453#issuecomment-1895415544
261- return null ;
262- }
263- }
264-
265- return $ queryResultType ;
266- }
267-
268220 private function getSimpleObjectHydratedReturnType (Type $ queryResultType ): ?Type
269221 {
270222 if ((new ObjectWithoutClassType ())->isSuperTypeOf ($ queryResultType )->yes ()) {
@@ -274,44 +226,4 @@ private function getSimpleObjectHydratedReturnType(Type $queryResultType): ?Type
274226 return null ;
275227 }
276228
277- private function getSingleScalarHydratedReturnType (Type $ queryResultType ): ?Type
278- {
279- $ queryResultType = $ this ->getScalarHydratedReturnType ($ queryResultType );
280- if ($ queryResultType === null || !$ queryResultType ->isConstantArray ()->yes ()) {
281- return null ;
282- }
283-
284- $ types = [];
285- foreach ($ queryResultType ->getConstantArrays () as $ constantArrayType ) {
286- $ values = $ constantArrayType ->getValueTypes ();
287- if (count ($ values ) !== 1 ) {
288- return null ;
289- }
290-
291- $ types [] = $ constantArrayType ->getFirstIterableValueType ();
292- }
293-
294- return TypeCombinator::union (...$ types );
295- }
296-
297- private function getScalarColumnHydratedReturnType (Type $ queryResultType ): ?Type
298- {
299- $ queryResultType = $ this ->getScalarHydratedReturnType ($ queryResultType );
300- if ($ queryResultType === null || !$ queryResultType ->isConstantArray ()->yes ()) {
301- return null ;
302- }
303-
304- $ types = [];
305- foreach ($ queryResultType ->getConstantArrays () as $ constantArrayType ) {
306- $ values = $ constantArrayType ->getValueTypes ();
307- if (count ($ values ) !== 1 ) {
308- return null ;
309- }
310-
311- $ types [] = $ constantArrayType ->getFirstIterableValueType ();
312- }
313-
314- return TypeCombinator::union (...$ types );
315- }
316-
317229}
0 commit comments