Skip to content
Snippets Groups Projects

Don't throw needless exception

1 file
+ 3
9
Compare changes
  • Side-by-side
  • Inline
+ 3
9
@@ -29,15 +29,9 @@ final class ReferenceUpgrader {
* Registers entities.
*/
public function registerEntity(EntityInterface $entity) {
$entityId = $entity->id() ?? $this->throwNeedsId();
$this->entities[$entity->getEntityTypeId()][$entityId] = $entity;
}
/**
* Throws exceptions on trying to register entities without id.
*/
private function throwNeedsId() {
throw new \RuntimeException("Can only register entity with ID.");
if ($entityId = $entity->id()) {
$this->entities[$entity->getEntityTypeId()][$entityId] = $entity;
}
}
/**
Loading