getEntityManager from OnFlushEventArgs is depreacated since 2.13
johanadivare opened this issue · 3 comments
johanadivare commented
getEntityManager from OnFlushEventArgs (and others) is depreacated since 2.13 see deprecated function:
/**
* Retrieve associated EntityManager.
*
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);
return $this->getObjectManager();
}
I like to create a rule which will change function call from getEntityManager
to getObjectManager
and create a constant DOCTRINE_213
that will have this rule let me know if that is something we want
alexander-schranz commented
@johanadivare This should be possible by configure a already existing rule in a new DoctrineORM213Set
:
$rectorConfig->ruleWithConfiguration(
RenameMethodRector::class,
[
// @see https://github.com/sulu/sulu/pull/6626
new MethodCallRename(
'Doctrine\ORM\Event\PreFlushEventArgs',
'getEntityManager',
'getObjectManager',
),
],
);
A new set for 2.13
would be needed to be created you can have a look at existing Sets e.g.:
- https://github.com/rectorphp/rector-doctrine/blob/main/config/sets/doctrine-orm-29.php
- also here need to be configured: https://github.com/rectorphp/rector-doctrine/blob/main/src/Set/DoctrineSetList.php
- and new test case for 213 ugprades is required (tests/Set/DoctrineORM213Set/..):
- example: https://github.com/rectorphp/rector-doctrine/blob/main/tests/Set/DoctrineORM29Set/DoctrineORM29SetTest.php
- example test config: https://github.com/rectorphp/rector-doctrine/blob/main/tests/Set/DoctrineORM29Set/config/configured_set.php
- and then a little before after fixture: https://github.com/rectorphp/rector-doctrine/blob/main/tests/Set/DoctrineORM29Set/Fixture/one_to_many.php.inc
@johanadivare Give it a try if you need any help let us know.
JohJohan commented
@alexander-schranz thank you for the information see #140 for what i build with your suggestions
johanadivare commented
Fixed with #140