add definition

This commit is contained in:
Tomas Votruba 2018-04-03 01:11:48 +02:00
parent e9988f6b4c
commit 8dc8d30be0

View File

@ -8,6 +8,9 @@ use PhpParser\Node\Identifier;
use Rector\BetterReflection\Reflector\SmartClassReflector;
use Rector\Node\PropertyFetchNodeFactory;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
use Symfony\Component\DependencyInjection\Definition;
final class ReplaceParentRepositoryCallsByRepositoryPropertyRector extends AbstractRector
{
@ -53,6 +56,7 @@ final class ReplaceParentRepositoryCallsByRepositoryPropertyRector extends Abstr
}
/**
* @todo should be part of reflection
* @return string[]
*/
private function getEntityRepositoryPublicMethodNames(): array
@ -65,4 +69,40 @@ final class ReplaceParentRepositoryCallsByRepositoryPropertyRector extends Abstr
return [];
}
public function getDefinition(): RectorDefinition
{
return new RectorDefinition(
'Handles method calls in child of Doctrine EntityRepository and moves them to "$this->repository" property.',
new CodeSample(
<<<'SAMPLE'
<?php
use Doctrine\ORM\EntityRepository;
class SomeRepository extends EntityRepository
{
public function someMethod()
{
return $this->findAll();
}
}
SAMPLE
,
<<<'SAMPLE_TWO'
<?php
use Doctrine\ORM\EntityRepository;
class SomeRepository extends EntityRepository
{
public function someMethod()
{
return $this->repository->findAll();
}
}
SAMPLE_TWO
)
);
}
}