25
25
use PHPStan \Type \TypeUtils ;
26
26
use PHPStan \Type \TypeWithClassName ;
27
27
use PHPStan \Type \VoidType ;
28
- use function count ;
29
28
30
29
final class QueryResultDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
31
30
{
@@ -42,9 +41,6 @@ final class QueryResultDynamicReturnTypeExtension implements DynamicMethodReturn
42
41
43
42
private const METHOD_HYDRATION_MODE = [
44
43
'getArrayResult ' => AbstractQuery::HYDRATE_ARRAY ,
45
- 'getScalarResult ' => AbstractQuery::HYDRATE_SCALAR ,
46
- 'getSingleColumnResult ' => AbstractQuery::HYDRATE_SCALAR_COLUMN ,
47
- 'getSingleScalarResult ' => AbstractQuery::HYDRATE_SINGLE_SCALAR ,
48
44
];
49
45
50
46
/** @var ObjectMetadataResolver */
@@ -130,26 +126,15 @@ private function getMethodReturnTypeForHydrationMode(
130
126
return null ;
131
127
}
132
128
133
- $ singleResult = false ;
134
129
switch ($ hydrationMode ->getValue ()) {
135
130
case AbstractQuery::HYDRATE_OBJECT :
136
131
break ;
137
132
case AbstractQuery::HYDRATE_ARRAY :
138
133
$ queryResultType = $ this ->getArrayHydratedReturnType ($ queryResultType );
139
134
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 ;
147
135
case AbstractQuery::HYDRATE_SIMPLEOBJECT :
148
136
$ queryResultType = $ this ->getSimpleObjectHydratedReturnType ($ queryResultType );
149
137
break ;
150
- case AbstractQuery::HYDRATE_SCALAR_COLUMN :
151
- $ queryResultType = $ this ->getScalarColumnHydratedReturnType ($ queryResultType );
152
- break ;
153
138
default :
154
139
return null ;
155
140
}
@@ -174,10 +159,6 @@ private function getMethodReturnTypeForHydrationMode(
174
159
$ queryResultType
175
160
);
176
161
default :
177
- if ($ singleResult ) {
178
- return $ queryResultType ;
179
- }
180
-
181
162
if ($ queryKeyType ->isNull ()->yes ()) {
182
163
return AccessoryArrayListType::intersectWith (new ArrayType (
183
164
new IntegerType (),
@@ -235,36 +216,6 @@ static function (Type $type, callable $traverse) use ($objectManager, &$mixedFou
235
216
return $ mixedFound ? null : $ queryResultType ;
236
217
}
237
218
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
-
268
219
private function getSimpleObjectHydratedReturnType (Type $ queryResultType ): ?Type
269
220
{
270
221
if ((new ObjectWithoutClassType ())->isSuperTypeOf ($ queryResultType )->yes ()) {
@@ -274,44 +225,4 @@ private function getSimpleObjectHydratedReturnType(Type $queryResultType): ?Type
274
225
return null ;
275
226
}
276
227
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
-
317
228
}
0 commit comments