Skip to content

Commit

Permalink
Fix return type of entity manager dynamic return
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lcobucci committed Aug 18, 2018
1 parent 74ba5ac commit 8784985
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ public function getTypeFromMethodCall(
return $mixedType;
}

$type = new ObjectType($argType->getValue());
if ($methodReflection->getName() === 'find') {
$type = TypeCombinator::addNull($type);
}

return $type;
return TypeCombinator::addNull(new ObjectType($argType->getValue()));
}

}
10 changes: 10 additions & 0 deletions tests/DoctrineIntegration/ORM/data/entityManagerDynamicReturn.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ public function findDynamicType(): void
public function getReferenceDynamicType(): void
{
$test = $this->entityManager->getReference(MyEntity::class, 1);

if ($test === null) {
throw new RuntimeException('Sorry, but no...');
}

$test->doSomething();
}

public function getPartialReferenceDynamicType(): void
{
$test = $this->entityManager->getPartialReference(MyEntity::class, 1);

if ($test === null) {
throw new RuntimeException('Sorry, but no...');
}

$test->doSomething();
}
}
Expand Down

0 comments on commit 8784985

Please sign in to comment.