You have injected the EntityManager via parameter $em. This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.
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:
functionsomeFunction(ManagerRegistry$registry){$em=$registry->getManager();$em->getConnection()->beginTransaction();try{// Do something.$em->getConnection()->commit();}catch(\Exception$ex){$em->getConnection()->rollback();$em->close();throw$ex;}}
If that code throws an exception and the EntityManager is closed. Any other
code which depends on the same instance of the EntityManager during this
request will fail.
On the other hand, if you instead inject the ManagerRegistry, the getManager()
method guarantees that you will always get a usable manager instance.
The call to DeepCloneAndSaveEvent::__construct() has too many arguments starting with $this->em.
This check compares calls to functions or methods with their respective definitions.
If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the
check may pick up the wrong definition and report false positives. One codebase
where this has been known to happen is Wordpress.
In this case you can add the @ignorePhpDoc
annotation to the duplicate definition and it will be ignored.
Loading history...
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, $this->em));
The call to DeepCloneAndSaveEvent::__construct() has too many arguments starting with $this->em.
This check compares calls to functions or methods with their respective definitions.
If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the
check may pick up the wrong definition and report false positives. One codebase
where this has been known to happen is Wordpress.
In this case you can add the @ignorePhpDoc
annotation to the duplicate definition and it will be ignored.
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.