Skip to content

Commit b3a7b16

Browse files
VincentLangletondrejmirtes
authored andcommitted
Avoid false positive about array result
1 parent c110e57 commit b3a7b16

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

Diff for: src/Type/Doctrine/Query/QueryResultDynamicReturnTypeExtension.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,14 @@ static function (Type $type, callable $traverse) use ($objectManager): Type {
199199
return new MixedType();
200200
}
201201

202-
return $objectManager->getMetadataFactory()->hasMetadataFor($type->getClassName())
203-
? new ArrayType(new MixedType(), new MixedType())
204-
: $traverse($type);
202+
if (!$objectManager->getMetadataFactory()->hasMetadataFor($type->getClassName())) {
203+
return $traverse($type);
204+
}
205+
206+
// We could return `new ArrayTyp(new MixedType(), new MixedType())`
207+
// but the lack of precision in the array keys/values would give false positive
208+
// @see https://github.com/phpstan/phpstan-doctrine/pull/412#issuecomment-1497092934
209+
return new MixedType();
205210
}
206211
);
207212
}

Diff for: tests/Type/Doctrine/data/QueryResult/queryResult.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -155,35 +155,35 @@ public function testReturnTypeOfQueryMethodsWithExplicitArrayHydrationMode(Entit
155155
');
156156

157157
assertType(
158-
'list<array>',
158+
'list<mixed>',
159159
$query->getResult(AbstractQuery::HYDRATE_ARRAY)
160160
);
161161
assertType(
162-
'list<array>',
162+
'list<mixed>',
163163
$query->getArrayResult()
164164
);
165165
assertType(
166-
'iterable<int, array>',
166+
'iterable<int, mixed>',
167167
$query->toIterable([], AbstractQuery::HYDRATE_ARRAY)
168168
);
169169
assertType(
170-
'list<array>',
170+
'list<mixed>',
171171
$query->execute(null, AbstractQuery::HYDRATE_ARRAY)
172172
);
173173
assertType(
174-
'list<array>',
174+
'list<mixed>',
175175
$query->executeIgnoreQueryCache(null, AbstractQuery::HYDRATE_ARRAY)
176176
);
177177
assertType(
178-
'list<array>',
178+
'list<mixed>',
179179
$query->executeUsingQueryCache(null, AbstractQuery::HYDRATE_ARRAY)
180180
);
181181
assertType(
182-
'array',
182+
'mixed',
183183
$query->getSingleResult(AbstractQuery::HYDRATE_ARRAY)
184184
);
185185
assertType(
186-
'array|null',
186+
'mixed',
187187
$query->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY)
188188
);
189189

0 commit comments

Comments
 (0)