mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-22 18:54:39 +01:00
[Doctrine] Skip ServiceEntityRepositoryParentCallToDIRector on non __construct method (#5333)
Co-authored-by: Dominik Firla <dominik.firla@carvago.com>
This commit is contained in:
parent
6f17c9c114
commit
453b8ba0b8
@ -11,6 +11,7 @@ use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\Doctrine\NodeFactory\RepositoryNodeFactory;
|
||||
use Rector\Doctrine\Type\RepositoryTypeFactory;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
@ -142,6 +143,10 @@ CODE_SAMPLE
|
||||
|
||||
private function shouldSkipClassMethod(ClassMethod $classMethod): bool
|
||||
{
|
||||
if (! $this->isName($classMethod, MethodName::CONSTRUCT)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @var string|null $parentClassName */
|
||||
$parentClassName = $classMethod->getAttribute(AttributeKey::PARENT_CLASS_NAME);
|
||||
if ($parentClassName === null) {
|
||||
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\Rector\ClassMethod\ServiceEntityRepositoryParentCallToDIRector\Fixture;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
use Rector\Doctrine\Tests\Rector\ClassMethod\ServiceEntityRepositoryParentCallToDIRector\Source\Project;
|
||||
|
||||
final class DoNotChangeOtherMethods extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Project::class);
|
||||
}
|
||||
|
||||
public function findBy(UuidInterface $id): void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\Rector\ClassMethod\ServiceEntityRepositoryParentCallToDIRector\Fixture;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
use Rector\Doctrine\Tests\Rector\ClassMethod\ServiceEntityRepositoryParentCallToDIRector\Source\Project;
|
||||
|
||||
final class DoNotChangeOtherMethods extends ServiceEntityRepository
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\ORM\EntityRepository<\Rector\Doctrine\Tests\Rector\ClassMethod\ServiceEntityRepositoryParentCallToDIRector\Source\Project>
|
||||
*/
|
||||
private \Doctrine\ORM\EntityRepository $repository;
|
||||
public function __construct(private \Doctrine\ORM\EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->repository = $entityManager->getRepository(Project::class);
|
||||
}
|
||||
|
||||
public function findBy(UuidInterface $id): void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user