Merge pull request #3155 from acrobat/add-extra-doctrine-alias-class

Add extra allowed interface to EntityAliasToClassConstantReferenceRector
This commit is contained in:
Tomas Votruba 2020-04-10 13:33:24 +02:00 committed by GitHub
commit a25adb10e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 4 deletions

View File

@ -4,8 +4,10 @@ declare(strict_types=1);
namespace Rector\Doctrine\Rector\MethodCall;
use Doctrine\Common\Persistence\ManagerRegistry as DeprecatedManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager as DeprecatedObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Nette\Utils\Strings;
use PhpParser\Node;
@ -20,6 +22,17 @@ use Rector\Core\RectorDefinition\RectorDefinition;
*/
final class EntityAliasToClassConstantReferenceRector extends AbstractRector
{
/**
* @var string[]
*/
private const ALLOWED_OBJECT_TYPES = [
EntityManagerInterface::class,
ObjectManager::class,
DeprecatedObjectManager::class,
ManagerRegistry::class,
DeprecatedManagerRegistry::class,
];
/**
* @var string[]
*/
@ -63,10 +76,7 @@ PHP
*/
public function refactor(Node $node): ?Node
{
if (! $this->isObjectTypes(
$node->var,
[EntityManagerInterface::class, ObjectManager::class, DeprecatedObjectManager::class]
)) {
if (! $this->isObjectTypes($node->var, self::ALLOWED_OBJECT_TYPES)) {
return null;
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
final class Test2Controller extends AbstractController
{
public function indexAction()
{
$this->getDoctrine()->getRepository('App:Post');
}
}
?>
-----
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
final class Test2Controller extends AbstractController
{
public function indexAction()
{
$this->getDoctrine()->getRepository(\App\Entity\Post::class);
}
}
?>