diff --git a/README.md b/README.md index c95411f9b..05730cc44 100644 --- a/README.md +++ b/README.md @@ -1770,48 +1770,6 @@ final class SomeService
-### NoRepositoryCallInDataFixtureRule - -Repository should not be called in data fixtures, as it can lead to tight coupling - -```yaml -rules: - - Symplify\PHPStanRules\Rules\Doctrine\NoRepositoryCallInDataFixtureRule -``` - -```php -use Doctrine\Common\DataFixtures\AbstractFixture; - -final class SomeFixture extends AbstractFixture -{ - public function load(ObjectManager $objectManager) - { - $someRepository = $objectManager->getRepository(SomeEntity::class); - $someEntity = $someRepository->get(1); - } -} -``` - -:x: - -
- -```php -use Doctrine\Common\DataFixtures\AbstractFixture; - -final class SomeFixture extends AbstractFixture -{ - public function load(ObjectManager $objectManager) - { - $someEntity = $this->getReference('some-entity-1'); - } -} -``` - -:+1: - -
- ---
diff --git a/config/doctrine-rules.neon b/config/doctrine-rules.neon index 6dd11ec2d..1ba9396a5 100644 --- a/config/doctrine-rules.neon +++ b/config/doctrine-rules.neon @@ -3,8 +3,6 @@ conditionalTags: phpstan.rules.rule: %symplify.doctrine% Symplify\PHPStanRules\Rules\Doctrine\NoParentRepositoryRule: phpstan.rules.rule: %symplify.doctrine% - Symplify\PHPStanRules\Rules\Doctrine\NoRepositoryCallInDataFixtureRule: - phpstan.rules.rule: %symplify.doctrine% Symplify\PHPStanRules\Rules\Doctrine\NoGetRepositoryOnServiceRepositoryEntityRule: phpstan.rules.rule: %symplify.doctrine% @@ -24,7 +22,6 @@ conditionalTags: services: - Symplify\PHPStanRules\Rules\Doctrine\NoGetRepositoryOutsideServiceRule - Symplify\PHPStanRules\Rules\Doctrine\NoParentRepositoryRule - - Symplify\PHPStanRules\Rules\Doctrine\NoRepositoryCallInDataFixtureRule - Symplify\PHPStanRules\Rules\Doctrine\NoGetRepositoryOnServiceRepositoryEntityRule - Symplify\PHPStanRules\Rules\Doctrine\NoDoctrineListenerWithoutContractRule - Symplify\PHPStanRules\Rules\Doctrine\RequireQueryBuilderOnRepositoryRule diff --git a/src/Enum/DoctrineClass.php b/src/Enum/DoctrineClass.php index dee33f0f0..1b0eaf54e 100644 --- a/src/Enum/DoctrineClass.php +++ b/src/Enum/DoctrineClass.php @@ -21,11 +21,6 @@ final class DoctrineClass */ public const ORM_SERVICE_REPOSITORY = 'Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository'; - /** - * @var string - */ - public const FIXTURE_INTERFACE = 'Doctrine\Common\DataFixtures\FixtureInterface'; - /** * @var string */ diff --git a/src/Rules/Doctrine/NoRepositoryCallInDataFixtureRule.php b/src/Rules/Doctrine/NoRepositoryCallInDataFixtureRule.php deleted file mode 100644 index 82869ee42..000000000 --- a/src/Rules/Doctrine/NoRepositoryCallInDataFixtureRule.php +++ /dev/null @@ -1,73 +0,0 @@ - - */ -final class NoRepositoryCallInDataFixtureRule implements Rule -{ - /** - * @var string - */ - public const ERROR_MESSAGE = 'Refactor read-data fixtures to write-only, make use of references'; - - public function getNodeType(): string - { - return MethodCall::class; - } - - /** - * @param MethodCall $node - * @return IdentifierRuleError[] - */ - public function processNode(Node $node, Scope $scope): array - { - if ($node->isFirstClassCallable()) { - return []; - } - - if (! $this->isDataFixtureClass($scope)) { - return []; - } - - if (! $node->name instanceof Identifier) { - return []; - } - - $methodName = $node->name->toString(); - if (! in_array($methodName, ['getRepository', 'find', 'findAll', 'findBy', 'findOneBy'], true)) { - return []; - } - - $identifierRuleError = RuleErrorBuilder::message(self::ERROR_MESSAGE) - ->identifier('doctrine.noRepositoryCallInDataFixtures') - ->build(); - - return [$identifierRuleError]; - } - - private function isDataFixtureClass(Scope $scope): bool - { - if (! $scope->isInClass()) { - return false; - } - - $classReflection = $scope->getClassReflection(); - return $classReflection->is(DoctrineClass::FIXTURE_INTERFACE); - } -} diff --git a/stubs/Doctrine/Bundle/FixturesBundle/Fixture.php b/stubs/Doctrine/Bundle/FixturesBundle/Fixture.php deleted file mode 100644 index c89d2e006..000000000 --- a/stubs/Doctrine/Bundle/FixturesBundle/Fixture.php +++ /dev/null @@ -1,15 +0,0 @@ -getRepository('someEntity'); - - $alsoNotAllowed = $notAllowed->find(5); - } -} diff --git a/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/Fixture/SomeRepositoryCallInFixture.php b/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/Fixture/SomeRepositoryCallInFixture.php deleted file mode 100644 index d0e8e1840..000000000 --- a/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/Fixture/SomeRepositoryCallInFixture.php +++ /dev/null @@ -1,18 +0,0 @@ -getRepository('someEntity'); - - $alsoNotAllowed = $notAllowed->find(5); - } -} diff --git a/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/NoRepositoryCallInDataFixtureRuleTest.php b/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/NoRepositoryCallInDataFixtureRuleTest.php deleted file mode 100644 index 1cc15c823..000000000 --- a/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/NoRepositoryCallInDataFixtureRuleTest.php +++ /dev/null @@ -1,44 +0,0 @@ -> $expectedErrorsWithLines - */ - #[DataProvider('provideData')] - public function testRule(string $filePath, array $expectedErrorsWithLines): void - { - $this->analyse([$filePath], $expectedErrorsWithLines); - } - - /** - * @return Iterator, mixed>> - */ - public static function provideData(): Iterator - { - yield [ - __DIR__ . '/Fixture/SomeRepositoryCallInFixture.php', - [ - [NoRepositoryCallInDataFixtureRule::ERROR_MESSAGE, 14], - [NoRepositoryCallInDataFixtureRule::ERROR_MESSAGE, 16], - ], - ]; - - yield [__DIR__ . '/Fixture/SkipNonFixtureClass.php', []]; - } - - protected function getRule(): Rule - { - return new NoRepositoryCallInDataFixtureRule(); - } -}