Conditions | 1 |
Paths | 1 |
Total Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
40 | public function deepCloneAndSave($entity) |
||
41 | { |
||
42 | $clonedEntity = clone $entity; |
||
43 | $this->eventDispatcher->dispatch(Events::DEEP_CLONE_AND_SAVE, new DeepCloneAndSaveEvent($entity, $clonedEntity)); |
||
44 | |||
45 | $this->em->persist($clonedEntity); |
||
46 | $this->em->flush(); |
||
47 | |||
48 | $this->eventDispatcher->dispatch(Events::POST_DEEP_CLONE_AND_SAVE, new DeepCloneAndSaveEvent($entity, $clonedEntity)); |
||
49 | |||
50 | return $clonedEntity; |
||
51 | } |
||
52 | } |
||
53 |
The
EntityManager
might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:If that code throws an exception and the
EntityManager
is closed. Any other code which depends on the same instance of theEntityManager
during this request will fail.On the other hand, if you instead inject the
ManagerRegistry
, thegetManager()
method guarantees that you will always get a usable manager instance.