Skip to content

Commit b3842be

Browse files
committed
Fix return type of entity manager dynamic return
The methods `EntityManagerInterface#getReference()` and `EntityManagerInterface#getPartialReference()` have nullable return. That's properly documented for `getReference()` but had to be fixed for `getPartialReference()`. Ref: doctrine/orm#7360
1 parent 1c8778f commit b3842be

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Type/Doctrine/EntityManagerFindDynamicReturnTypeExtension.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ public function getTypeFromMethodCall(
4343
return $mixedType;
4444
}
4545

46-
$type = new ObjectType($argType->getValue());
47-
if ($methodReflection->getName() === 'find') {
48-
$type = TypeCombinator::addNull($type);
49-
}
50-
51-
return $type;
46+
return TypeCombinator::addNull(new ObjectType($argType->getValue()));
5247
}
5348

5449
}

tests/DoctrineIntegration/ORM/data/entityManagerDynamicReturn.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@ public function findDynamicType(): void
3131
public function getReferenceDynamicType(): void
3232
{
3333
$test = $this->entityManager->getReference(MyEntity::class, 1);
34+
35+
if ($test === null) {
36+
throw new RuntimeException('Sorry, but no...');
37+
}
38+
3439
$test->doSomething();
3540
}
3641

3742
public function getPartialReferenceDynamicType(): void
3843
{
3944
$test = $this->entityManager->getPartialReference(MyEntity::class, 1);
45+
46+
if ($test === null) {
47+
throw new RuntimeException('Sorry, but no...');
48+
}
49+
4050
$test->doSomething();
4151
}
4252
}

0 commit comments

Comments
 (0)