-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[code-quality] Add GetRepositoryServiceLocatorToRepositoryServiceInje…
…ctionRector (#368) * [code-quality] Add GetRepositoryServiceLocatorToRepositoryServiceInjectionRector * skip callable
- Loading branch information
1 parent
33f8d9b
commit f058b83
Showing
18 changed files
with
531 additions
and
17 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...ceLocatorToRepositoryServiceInjectionRector/Fixture/get_odm_repository_on_service.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Fixture; | ||
|
||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\Entity\SomeEntityUsingService; | ||
|
||
final class GetODMRepositoryOnService | ||
{ | ||
public function run(DocumentManager $entityManager) | ||
{ | ||
$someRepository = $entityManager->getRepository(SomeEntityUsingService::class); | ||
|
||
return $someRepository->find(1); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Fixture; | ||
|
||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\Entity\SomeEntityUsingService; | ||
|
||
final class GetODMRepositoryOnService | ||
{ | ||
public function __construct(private readonly \Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\SomeServiceRepository $someEntityUsingServiceRepository) | ||
{ | ||
} | ||
public function run(DocumentManager $entityManager) | ||
{ | ||
$someRepository = $this->someEntityUsingServiceRepository; | ||
|
||
return $someRepository->find(1); | ||
} | ||
} | ||
|
||
?> |
40 changes: 40 additions & 0 deletions
40
...erviceLocatorToRepositoryServiceInjectionRector/Fixture/get_repository_on_service.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Fixture; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\Entity\SomeEntityUsingORMService; | ||
|
||
final class GetRepositoryOnService | ||
{ | ||
public function run(EntityManagerInterface $entityManager) | ||
{ | ||
$someRepository = $entityManager->getRepository(SomeEntityUsingORMService::class); | ||
|
||
return $someRepository->find(1); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Fixture; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\Entity\SomeEntityUsingORMService; | ||
|
||
final class GetRepositoryOnService | ||
{ | ||
public function __construct(private readonly \Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\SomeORMServiceRepository $someEntityUsingORMServiceRepository) | ||
{ | ||
} | ||
public function run(EntityManagerInterface $entityManager) | ||
{ | ||
$someRepository = $this->someEntityUsingORMServiceRepository; | ||
|
||
return $someRepository->find(1); | ||
} | ||
} | ||
|
||
?> |
13 changes: 13 additions & 0 deletions
13
...tRepositoryServiceLocatorToRepositoryServiceInjectionRector/Fixture/skip_callable.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Fixture; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
final class SkipCallable | ||
{ | ||
public function run(EntityManagerInterface $entityManager) | ||
{ | ||
$someRepository = $entityManager->getRepository(...); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ryServiceLocatorToRepositoryServiceInjectionRector/Fixture/skip_inside_repository.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Fixture; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\EntityRepository; | ||
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\Entity\SomeEntityUsingService; | ||
|
||
final class SkipInsideRepository extends EntityRepository | ||
{ | ||
public function run(EntityManagerInterface $entityManager) | ||
{ | ||
$someRepository = $entityManager->getRepository(SomeEntityUsingService::class); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...viceInjectionRector/GetRepositoryServiceLocatorToRepositoryServiceInjectionRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class GetRepositoryServiceLocatorToRepositoryServiceInjectionRectorTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...viceLocatorToRepositoryServiceInjectionRector/Source/Entity/SomeEntityUsingORMService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\Entity; | ||
|
||
/** | ||
* @ORM\Entity(repositoryClass="Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\SomeORMServiceRepository") | ||
*/ | ||
class SomeEntityUsingORMService | ||
{ | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...ServiceLocatorToRepositoryServiceInjectionRector/Source/Entity/SomeEntityUsingService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\Entity; | ||
|
||
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source\SomeServiceRepository; | ||
|
||
/** | ||
* @ORM\Entity(repositoryClass=SomeServiceRepository::class) | ||
*/ | ||
class SomeEntityUsingService | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
...itoryServiceLocatorToRepositoryServiceInjectionRector/Source/SomeORMServiceRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
|
||
final class SomeORMServiceRepository extends ServiceEntityRepository | ||
{ | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...positoryServiceLocatorToRepositoryServiceInjectionRector/Source/SomeServiceRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector\Source; | ||
|
||
use Doctrine\Bundle\MongoDBBundle\Repository\ServiceDocumentRepository; | ||
|
||
final class SomeServiceRepository extends ServiceDocumentRepository | ||
{ | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
.../GetRepositoryServiceLocatorToRepositoryServiceInjectionRector/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Doctrine\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(GetRepositoryServiceLocatorToRepositoryServiceInjectionRector::class); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.