mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 19:53:14 +01:00
Merge pull request #3155 from acrobat/add-extra-doctrine-alias-class
Add extra allowed interface to EntityAliasToClassConstantReferenceRector
This commit is contained in:
commit
a25adb10e5
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user