Skip to content

Commit a0041f7

Browse files
lcobucciondrejmirtes
authored andcommitted
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()`.
1 parent 5c58d99 commit a0041f7

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
@@ -32,12 +32,22 @@ public function findDynamicType(): void
3232
public function getReferenceDynamicType(): void
3333
{
3434
$test = $this->entityManager->getReference(MyEntity::class, 1);
35+
36+
if ($test === null) {
37+
throw new RuntimeException('Sorry, but no...');
38+
}
39+
3540
$test->doSomething();
3641
}
3742

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

0 commit comments

Comments
 (0)