Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

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;
Expand All @@ -20,6 +22,17 @@
*/
final class EntityAliasToClassConstantReferenceRector extends AbstractRector
{
/**
* @var string[]
*/
private const ALLOWED_OBJECT_TYPES = [
EntityManagerInterface::class,
ObjectManager::class,
DeprecatedObjectManager::class,
ManagerRegistry::class,
DeprecatedManagerRegistry::class,
];

/**
* @var string[]
*/
Expand Down Expand Up @@ -63,10 +76,7 @@ public function getNodeTypes(): array
*/
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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

?>