Skip to content

Commit

Permalink
Avoid false positive about array result
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and ondrejmirtes committed Apr 5, 2023
1 parent c110e57 commit b3a7b16
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,14 @@ static function (Type $type, callable $traverse) use ($objectManager): Type {
return new MixedType();
}

return $objectManager->getMetadataFactory()->hasMetadataFor($type->getClassName())
? new ArrayType(new MixedType(), new MixedType())
: $traverse($type);
if (!$objectManager->getMetadataFactory()->hasMetadataFor($type->getClassName())) {
return $traverse($type);
}

// We could return `new ArrayTyp(new MixedType(), new MixedType())`
// but the lack of precision in the array keys/values would give false positive
// @see https://github.com/phpstan/phpstan-doctrine/pull/412#issuecomment-1497092934
return new MixedType();
}
);
}
Expand Down
16 changes: 8 additions & 8 deletions tests/Type/Doctrine/data/QueryResult/queryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,35 @@ public function testReturnTypeOfQueryMethodsWithExplicitArrayHydrationMode(Entit
');

assertType(
'list<array>',
'list<mixed>',
$query->getResult(AbstractQuery::HYDRATE_ARRAY)
);
assertType(
'list<array>',
'list<mixed>',
$query->getArrayResult()
);
assertType(
'iterable<int, array>',
'iterable<int, mixed>',
$query->toIterable([], AbstractQuery::HYDRATE_ARRAY)
);
assertType(
'list<array>',
'list<mixed>',
$query->execute(null, AbstractQuery::HYDRATE_ARRAY)
);
assertType(
'list<array>',
'list<mixed>',
$query->executeIgnoreQueryCache(null, AbstractQuery::HYDRATE_ARRAY)
);
assertType(
'list<array>',
'list<mixed>',
$query->executeUsingQueryCache(null, AbstractQuery::HYDRATE_ARRAY)
);
assertType(
'array',
'mixed',
$query->getSingleResult(AbstractQuery::HYDRATE_ARRAY)
);
assertType(
'array|null',
'mixed',
$query->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY)
);

Expand Down

0 comments on commit b3a7b16

Please sign in to comment.