Skip to content

Commit 24fc706

Browse files
committed
Revert "Avoid false positive about array result"
This reverts commit b3a7b16.
1 parent 84bf895 commit 24fc706

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/Type/Doctrine/Query/QueryResultDynamicReturnTypeExtension.php

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

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();
202+
return $objectManager->getMetadataFactory()->hasMetadataFor($type->getClassName())
203+
? new ArrayType(new MixedType(), new MixedType())
204+
: $traverse($type);
210205
}
211206
);
212207
}

tests/Type/Doctrine/data/QueryResult/queryResult.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,35 +155,35 @@ public function testReturnTypeOfQueryMethodsWithExplicitArrayHydrationMode(Entit
155155
');
156156

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

0 commit comments

Comments
 (0)