Skip to content

Commit 48b40f9

Browse files
Introduce default hydration mode
1 parent 31a924b commit 48b40f9

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/Type/Doctrine/HydrationModeReturnTypeResolver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function getMethodReturnTypeForHydrationMode(
2525
Type $hydrationMode,
2626
Type $queryKeyType,
2727
Type $queryResultType,
28-
?ObjectManager $objectManager
28+
Type $defaultHydrationModeType
2929
): ?Type
3030
{
3131
$isVoidType = (new VoidType())->isSuperTypeOf($queryResultType);
@@ -42,6 +42,10 @@ public function getMethodReturnTypeForHydrationMode(
4242
return null;
4343
}
4444

45+
if ($hydrationMode->isNull()->yes()) {
46+
$hydrationMode = $defaultHydrationModeType;
47+
}
48+
4549
if (!$hydrationMode instanceof ConstantIntegerType) {
4650
return null;
4751
}

src/Type/Doctrine/Query/QueryResultDynamicReturnTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getTypeFromMethodCall(
8484
$hydrationMode,
8585
$queryType->getTemplateType(AbstractQuery::class, 'TKey'),
8686
$queryType->getTemplateType(AbstractQuery::class, 'TResult'),
87-
$this->objectMetadataResolver->getObjectManager(),
87+
$queryType->getTemplateType(AbstractQuery::class, 'THydrationMode'),
8888
);
8989
}
9090

stubs/ORM/AbstractQuery.stub

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use Doctrine\ORM\NoResultException;
99
/**
1010
* @template-covariant TKey The type of column used in indexBy
1111
* @template-covariant TResult The type of results returned by this query in HYDRATE_OBJECT mode
12+
* @template-covariant THydrationMode of string|AbstractQuery::HYDRATE_* = AbstractQuery::HYDRATE_OBJECT The default hydration mode when none is provided
1213
*/
1314
abstract class AbstractQuery
1415
{
@@ -84,4 +85,13 @@ abstract class AbstractQuery
8485
{
8586
}
8687

88+
/**
89+
* @template TNewHydrationMode of string|AbstractQuery::HYDRATE_*
90+
* @param TNewHydrationMode $hydrationMode
91+
* @phpstan-self-out self<TKey, TResult, TNewHydrationMode>
92+
*/
93+
public function setHydrationMode(string|int $hydrationMode): static
94+
{
95+
}
96+
8797
}

stubs/ORM/Query.stub

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ namespace Doctrine\ORM;
55
/**
66
* @template-covariant TKey The type of column used in indexBy
77
* @template-covariant TResult The type of results returned by this query in HYDRATE_OBJECT mode
8+
* @template-covariant THydrationMode of int|string The default hydration mode when none is provided
89
*
9-
* @extends AbstractQuery<TKey, TResult>
10+
* @extends AbstractQuery<TKey, TResult, THydrationMode>
1011
*/
1112
final class Query extends AbstractQuery
1213
{

0 commit comments

Comments
 (0)