rectorphp/rector-doctrine

getEntityManager from OnFlushEventArgs is depreacated since 2.13

johanadivare opened this issue · 3 comments

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

@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.:

@johanadivare Give it a try if you need any help let us know.

@alexander-schranz thank you for the information see #140 for what i build with your suggestions

Fixed with #140