mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
cover list with multiple arguments
This commit is contained in:
parent
7c5b6c2f27
commit
3c2683f13c
1
ecs.yaml
1
ecs.yaml
@ -151,6 +151,7 @@ parameters:
|
||||
- 'packages/Php72/src/Rector/Each/ListEachRector.php'
|
||||
- 'packages/DeadCode/src/Rector/ClassMethod/RemoveOverriddenValuesRector.php'
|
||||
- 'packages/PhpSpecToPHPUnit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php'
|
||||
- 'packages/CakePHPToSymfony/tests/Rector/Class_/CakePHPModelToDoctrineRepositoryRector/CakePHPModelToDoctrineRepositoryRectorTest.php'
|
||||
|
||||
PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer:
|
||||
- 'packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php'
|
||||
|
@ -83,7 +83,6 @@ final class DoctrineRepositoryClassMethodManipulator
|
||||
if ($findKind === 'first') {
|
||||
$this->refactorFindFirst($methodCall, $entityClass);
|
||||
return $methodCall;
|
||||
|
||||
}
|
||||
|
||||
if ($findKind === 'threaded') {
|
||||
@ -251,18 +250,20 @@ final class DoctrineRepositoryClassMethodManipulator
|
||||
private function refactorFindList(string $entityClass): MethodCall
|
||||
{
|
||||
// @see https://stackoverflow.com/a/42913902/1348344
|
||||
$thisRepositoryPropertyFetch = new PropertyFetch(new Variable('this'), new Name('repository'));
|
||||
$thisRepositoryPropertyFetch = new PropertyFetch(new Variable('this'), new Identifier('repository'));
|
||||
|
||||
$entityAliasLetter = strtolower($entityClass[0]);
|
||||
|
||||
$createQueryBuilderMethodCall = new MethodCall($thisRepositoryPropertyFetch, new Identifier('createQueryBuilder'), [
|
||||
new Arg(new String_($entityAliasLetter))
|
||||
]);
|
||||
$createQueryBuilderMethodCall = new MethodCall($thisRepositoryPropertyFetch, new Identifier(
|
||||
'createQueryBuilder'
|
||||
), [new Arg(new String_($entityAliasLetter))]);
|
||||
|
||||
$getQueryMethodCall = new MethodCall($createQueryBuilderMethodCall, new Identifier('getQuery'));
|
||||
|
||||
$getResultMethodCall = new MethodCall($getQueryMethodCall, new Identifier('getResult'));
|
||||
$hydrateArrayClassConstFetch = new ClassConstFetch(new FullyQualified('Doctrine\ORM\Query'), new Identifier('HYDRATE_ARRAY'));
|
||||
$hydrateArrayClassConstFetch = new ClassConstFetch(new FullyQualified('Doctrine\ORM\Query'), new Identifier(
|
||||
'HYDRATE_ARRAY'
|
||||
));
|
||||
$getResultMethodCall->args[] = new Arg($hydrateArrayClassConstFetch);
|
||||
|
||||
return $getResultMethodCall;
|
||||
|
@ -52,6 +52,13 @@ final class CakePHPModelToDoctrineRepositoryRectorTest extends AbstractRectorTes
|
||||
$this->getTempPath() . '/FindListRepository.php',
|
||||
__DIR__ . '/Source/ExpectedFindListRepository.php',
|
||||
];
|
||||
|
||||
// WIP
|
||||
// yield [
|
||||
// __DIR__ . '/Fixture/find_list_with_one_argument.php.inc',
|
||||
// $this->getTempPath() . '/FindListWithOneArgumentRepository.php',
|
||||
// __DIR__ . '/Source/ExpectedFindListWithOneArgumentRepository.php',
|
||||
// ];
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\Class_\CakePHPModelToDoctrineRepositoryRector\Fixture;
|
||||
|
||||
class FindListWithOneArgument extends \AppModel
|
||||
{
|
||||
public function getList()
|
||||
{
|
||||
return $this->find('list', [
|
||||
'fields' => ['User.username']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\Class_\CakePHPModelToDoctrineRepositoryRector\Fixture;
|
||||
|
||||
class FindListWithOneArgument
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\Class_\CakePHPModelToDoctrineRepositoryRector\Fixture;
|
||||
|
||||
class FindListWithOneArgumentRepository
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\ORM\EntityRepository
|
||||
*/
|
||||
private $repository;
|
||||
public function __construct(\Doctrine\ORM\EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->repository = $entityManager->getRepository(\FindListWithOneArgument::class);
|
||||
}
|
||||
public function getList()
|
||||
{
|
||||
return $this->repository->createQueryBuilder('f')->getQuery()->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user