From a92f4c1e2d103477df4ba949d2879ce68386fee7 Mon Sep 17 00:00:00 2001 From: Krystian Marcisz Date: Wed, 4 Nov 2020 22:51:11 +0100 Subject: [PATCH] [DoctrineCodeQuality] Remove redundant default values from annotations (#4542) * Move duplicated getAttributableItems() method to abstract parent * Add removeItem() method to AbstractTagValueNode class * Add RemoveRedundantDefaultAnnotationValuesRector rule with tests * Link second test case of RemoveRedundantDefaultAnnotationValuesRector * Add to set and docs * Rename variable in DoctrineClassAnalyzer::matchDoctrineEntityTagValueNode() * Remove redundant docblocks in RemoveRedundantDefaultAnnotationValuesRector * Extract hasItemWithDefaultValue method in RemoveRedundantDefaultAnnotationValuesRector * Optimize RemoveRedundantDefaultAnnotationValuesRector * Split rule into two separate: one for Property and one for Class_ * PHP CS Fixer * PHPStan --- config/set/doctrine-code-quality.php | 4 + docs/rector_rules_overview.md | 49 ++++- .../PhpDocNode/AbstractTagValueNode.php | 5 + .../Doctrine/AbstractDoctrineTagValueNode.php | 7 + .../Doctrine/Property_/ColumnTagValueNode.php | 8 - .../Property_/GeneratedValueTagValueNode.php | 8 - .../Doctrine/Property_/IdTagValueNode.php | 8 - .../Property_/JoinColumnTagValueNode.php | 8 - .../Property_/ManyToManyTagValueNode.php | 8 - .../NodeAnalyzer/DoctrineClassAnalyzer.php | 24 +++ .../NodeAnalyzer/DoctrinePropertyAnalyzer.php | 60 ++++++ .../DoctrineItemDefaultValueManipulator.php | 53 +++++ ...dantDefaultClassAnnotationValuesRector.php | 107 ++++++++++ ...tDefaultPropertyAnnotationValuesRector.php | 191 ++++++++++++++++++ .../Fixture/Entity/read_only_false.php.inc | 29 +++ .../Fixture/Entity/read_only_skipped.php.inc | 14 ++ ...DefaultClassAnnotationValuesRectorTest.php | 31 +++ .../Fixture/Column/nullable_false.php.inc | 39 ++++ .../Fixture/Column/nullable_skipped.php.inc | 20 ++ .../Fixture/Column/precision_skipped.php.inc | 19 ++ .../Fixture/Column/precision_zero.php.inc | 39 ++++ .../Fixture/Column/scale_skipped.php.inc | 19 ++ .../Fixture/Column/scale_zero.php.inc | 39 ++++ .../Fixture/Column/unique_false.php.inc | 39 ++++ .../Fixture/Column/unique_skipped.php.inc | 19 ++ .../GeneratedValue/strategy_auto.php.inc | 43 ++++ .../GeneratedValue/strategy_skipped.php.inc | 21 ++ .../JoinColumn/nullable_skipped.php.inc | 21 ++ .../Fixture/JoinColumn/nullable_true.php.inc | 41 ++++ .../referenced_column_name_id.php.inc | 41 ++++ .../referenced_column_name_skipped.php.inc | 20 ++ .../Fixture/JoinColumn/unique_false.php.inc | 41 ++++ .../Fixture/JoinColumn/unique_skipped.php.inc | 20 ++ .../Fixture/ManyToMany/fetch_lazy.php.inc | 39 ++++ .../Fixture/ManyToMany/fetch_skipped.php.inc | 20 ++ .../ManyToMany/orphan_removal_false.php.inc | 39 ++++ .../ManyToMany/orphan_removal_skipped.php.inc | 20 ++ .../Fixture/ManyToOne/fetch_lazy.php.inc | 39 ++++ .../Fixture/ManyToOne/fetch_skipped.php.inc | 20 ++ .../Fixture/OneToMany/fetch_lazy.php.inc | 39 ++++ .../Fixture/OneToMany/fetch_skipped.php.inc | 20 ++ .../OneToMany/orphan_removal_false.php.inc | 39 ++++ .../OneToMany/orphan_removal_skipped.php.inc | 20 ++ .../Fixture/OneToOne/fetch_lazy.php.inc | 39 ++++ .../Fixture/OneToOne/fetch_skipped.php.inc | 20 ++ .../OneToOne/orphan_removal_false.php.inc | 39 ++++ .../OneToOne/orphan_removal_skipped.php.inc | 20 ++ ...aultPropertyAnnotationValuesRectorTest.php | 31 +++ .../Source/Training.php | 10 + 49 files changed, 1508 insertions(+), 41 deletions(-) create mode 100644 rules/doctrine-code-quality/src/NodeAnalyzer/DoctrineClassAnalyzer.php create mode 100644 rules/doctrine-code-quality/src/NodeManipulator/DoctrineItemDefaultValueManipulator.php create mode 100644 rules/doctrine-code-quality/src/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector.php create mode 100644 rules/doctrine-code-quality/src/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector.php create mode 100644 rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/Fixture/Entity/read_only_false.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/Fixture/Entity/read_only_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/RemoveRedundantDefaultClassAnnotationValuesRectorTest.php create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/nullable_false.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/nullable_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/precision_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/precision_zero.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/scale_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/scale_zero.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/unique_false.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/unique_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/GeneratedValue/strategy_auto.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/GeneratedValue/strategy_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/nullable_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/nullable_true.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/referenced_column_name_id.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/referenced_column_name_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/unique_false.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/unique_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/fetch_lazy.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/fetch_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/orphan_removal_false.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/orphan_removal_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToOne/fetch_lazy.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToOne/fetch_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/fetch_lazy.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/fetch_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/orphan_removal_false.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/orphan_removal_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/fetch_lazy.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/fetch_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/orphan_removal_false.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/orphan_removal_skipped.php.inc create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/RemoveRedundantDefaultPropertyAnnotationValuesRectorTest.php create mode 100644 rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Source/Training.php diff --git a/config/set/doctrine-code-quality.php b/config/set/doctrine-code-quality.php index d1bace4e7d3..dd1c42b7813 100644 --- a/config/set/doctrine-code-quality.php +++ b/config/set/doctrine-code-quality.php @@ -5,11 +5,13 @@ declare(strict_types=1); use Rector\Doctrine\Rector\Class_\ManagerRegistryGetManagerToEntityManagerRector; use Rector\DoctrineCodeQuality\Rector\Class_\InitializeDefaultEntityCollectionRector; use Rector\DoctrineCodeQuality\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector; +use Rector\DoctrineCodeQuality\Rector\Class_\RemoveRedundantDefaultClassAnnotationValuesRector; use Rector\DoctrineCodeQuality\Rector\ClassMethod\MakeEntityDateTimePropertyDateTimeInterfaceRector; use Rector\DoctrineCodeQuality\Rector\ClassMethod\MakeEntitySetterNullabilityInSyncWithPropertyRector; use Rector\DoctrineCodeQuality\Rector\Property\ChangeBigIntEntityPropertyToIntTypeRector; use Rector\DoctrineCodeQuality\Rector\Property\CorrectDefaultTypesOnEntityPropertyRector; use Rector\DoctrineCodeQuality\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector; +use Rector\DoctrineCodeQuality\Rector\Property\RemoveRedundantDefaultPropertyAnnotationValuesRector; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { @@ -22,4 +24,6 @@ return static function (ContainerConfigurator $containerConfigurator): void { $services->set(CorrectDefaultTypesOnEntityPropertyRector::class); $services->set(ChangeBigIntEntityPropertyToIntTypeRector::class); $services->set(ImproveDoctrineCollectionDocTypeInEntityRector::class); + $services->set(RemoveRedundantDefaultPropertyAnnotationValuesRector::class); + $services->set(RemoveRedundantDefaultClassAnnotationValuesRector::class); }; diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index f135c42db49..3b3fd86ae98 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -13,7 +13,7 @@ - [DeadCode](#deadcode) (41) - [Defluent](#defluent) (8) - [Doctrine](#doctrine) (17) -- [DoctrineCodeQuality](#doctrinecodequality) (9) +- [DoctrineCodeQuality](#doctrinecodequality) (11) - [DoctrineGedmoToKnplabs](#doctrinegedmotoknplabs) (7) - [DowngradePhp71](#downgradephp71) (3) - [DowngradePhp72](#downgradephp72) (2) @@ -4449,6 +4449,53 @@ Turns parent EntityRepository class to constructor dependency

+### `RemoveRedundantDefaultPropertyAnnotationValuesRector` + +- class: [`Rector\DoctrineCodeQuality\Rector\Property\RemoveRedundantDefaultPropertyAnnotationValuesRector`](/rules/doctrine-code-quality/src/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector.php) +- [test fixtures](/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture) + +Removes redundant default values from Doctrine ORM annotations on class property level + +```diff + use Doctrine\ORM\Mapping as ORM; + + /** + * @ORM\Entity + */ + class SomeClass + { + /** + * @ORM\ManyToOne(targetEntity=Training::class) +- * @ORM\JoinColumn(name="training", unique=false) ++ * @ORM\JoinColumn(name="training") + */ + private $training; + } +``` + +

+ +### `RemoveRedundantDefaultPropertyAnnotationValuesRector` + +- class: [`Rector\DoctrineCodeQuality\Rector\Class_\RemoveRedundantDefaultClassAnnotationValuesRector`](/rules/doctrine-code-quality/src/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector.php) +- [test fixtures](/rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/Fixture) + +Removes redundant default values from Doctrine ORM annotations on class level + +```diff + use Doctrine\ORM\Mapping as ORM; + + /** +- * @ORM\Entity(readOnly=false) ++ * @ORM\Entity() + */ + class SomeClass + { + } +``` + +

+ ## DoctrineGedmoToKnplabs ### `BlameableBehaviorRector` diff --git a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/AbstractTagValueNode.php b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/AbstractTagValueNode.php index d360b9fac95..0f8e2a50048 100644 --- a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/AbstractTagValueNode.php +++ b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/AbstractTagValueNode.php @@ -65,6 +65,11 @@ abstract class AbstractTagValueNode implements AttributeAwareNodeInterface, PhpD $this->items[$key] = $value; } + public function removeItem(string $key): void + { + unset($this->items[$key]); + } + /** * @param mixed[] $contentItems * @return mixed[] diff --git a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/AbstractDoctrineTagValueNode.php b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/AbstractDoctrineTagValueNode.php index b3e1e66a546..cfe38b9a2c2 100644 --- a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/AbstractDoctrineTagValueNode.php +++ b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/AbstractDoctrineTagValueNode.php @@ -10,4 +10,11 @@ use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode; abstract class AbstractDoctrineTagValueNode extends AbstractTagValueNode implements DoctrineTagNodeInterface, ShortNameAwareTagInterface { + /** + * @return mixed[] + */ + public function getAttributableItems(): array + { + return $this->filterOutMissingItems($this->items); + } } diff --git a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/ColumnTagValueNode.php b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/ColumnTagValueNode.php index 9373ab291f5..71ae5bb44b2 100644 --- a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/ColumnTagValueNode.php +++ b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/ColumnTagValueNode.php @@ -37,14 +37,6 @@ final class ColumnTagValueNode extends AbstractDoctrineTagValueNode implements P return $this->items['options'] ?? []; } - /** - * @return mixed[] - */ - public function getAttributableItems(): array - { - return $this->filterOutMissingItems($this->items); - } - public function getAttributeClassName(): string { return 'TBA'; diff --git a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/GeneratedValueTagValueNode.php b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/GeneratedValueTagValueNode.php index e71bcdd6dac..017396ab874 100644 --- a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/GeneratedValueTagValueNode.php +++ b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/GeneratedValueTagValueNode.php @@ -23,14 +23,6 @@ final class GeneratedValueTagValueNode extends AbstractDoctrineTagValueNode impl return 'strategy'; } - /** - * @return mixed[] - */ - public function getAttributableItems(): array - { - return $this->filterOutMissingItems($this->items); - } - public function getAttributeClassName(): string { return 'TBA'; diff --git a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/IdTagValueNode.php b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/IdTagValueNode.php index 2047696f024..1d2fee0256b 100644 --- a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/IdTagValueNode.php +++ b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/IdTagValueNode.php @@ -14,14 +14,6 @@ final class IdTagValueNode extends AbstractDoctrineTagValueNode implements PhpAt return '@ORM\Id'; } - /** - * @return mixed[] - */ - public function getAttributableItems(): array - { - return $this->filterOutMissingItems($this->items); - } - public function getAttributeClassName(): string { return 'TBA'; diff --git a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/JoinColumnTagValueNode.php b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/JoinColumnTagValueNode.php index 7863f1bbc4b..1edff4a4a14 100644 --- a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/JoinColumnTagValueNode.php +++ b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/JoinColumnTagValueNode.php @@ -52,14 +52,6 @@ final class JoinColumnTagValueNode extends AbstractDoctrineTagValueNode implemen $this->shortName = $shortName; } - /** - * @return mixed[] - */ - public function getAttributableItems(): array - { - return $this->filterOutMissingItems($this->items); - } - public function getAttributeClassName(): string { return 'TBA'; diff --git a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/ManyToManyTagValueNode.php b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/ManyToManyTagValueNode.php index 9caecfd46ea..0152eac7c10 100644 --- a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/ManyToManyTagValueNode.php +++ b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/ManyToManyTagValueNode.php @@ -72,14 +72,6 @@ final class ManyToManyTagValueNode extends AbstractDoctrineTagValueNode implemen return '@ORM\ManyToMany'; } - /** - * @return mixed[] - */ - public function getAttributableItems(): array - { - return $this->filterOutMissingItems($this->items); - } - public function getAttributeClassName(): string { return 'TBA'; diff --git a/rules/doctrine-code-quality/src/NodeAnalyzer/DoctrineClassAnalyzer.php b/rules/doctrine-code-quality/src/NodeAnalyzer/DoctrineClassAnalyzer.php new file mode 100644 index 00000000000..5f8d9bce90e --- /dev/null +++ b/rules/doctrine-code-quality/src/NodeAnalyzer/DoctrineClassAnalyzer.php @@ -0,0 +1,24 @@ +getAttribute(AttributeKey::PHP_DOC_INFO); + if ($phpDocInfo === null) { + return null; + } + + return $phpDocInfo->getByType(EntityTagValueNode::class); + } +} diff --git a/rules/doctrine-code-quality/src/NodeAnalyzer/DoctrinePropertyAnalyzer.php b/rules/doctrine-code-quality/src/NodeAnalyzer/DoctrinePropertyAnalyzer.php index 8b681218dae..14b92cb5b33 100644 --- a/rules/doctrine-code-quality/src/NodeAnalyzer/DoctrinePropertyAnalyzer.php +++ b/rules/doctrine-code-quality/src/NodeAnalyzer/DoctrinePropertyAnalyzer.php @@ -7,7 +7,12 @@ namespace Rector\DoctrineCodeQuality\NodeAnalyzer; use PhpParser\Node\Stmt\Property; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\ColumnTagValueNode; +use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\GeneratedValueTagValueNode; +use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\JoinColumnTagValueNode; +use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\ManyToManyTagValueNode; +use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\ManyToOneTagValueNode; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\OneToManyTagValueNode; +use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\OneToOneTagValueNode; use Rector\NodeTypeResolver\Node\AttributeKey; final class DoctrinePropertyAnalyzer @@ -33,4 +38,59 @@ final class DoctrinePropertyAnalyzer return $phpDocInfo->getByType(OneToManyTagValueNode::class); } + + public function matchDoctrineOneToOneTagValueNode(Property $property): ?OneToOneTagValueNode + { + /** @var PhpDocInfo|null $phpDocInfo */ + $phpDocInfo = $property->getAttribute(AttributeKey::PHP_DOC_INFO); + if ($phpDocInfo === null) { + return null; + } + + return $phpDocInfo->getByType(OneToOneTagValueNode::class); + } + + public function matchDoctrineManyToManyTagValueNode(Property $property): ?ManyToManyTagValueNode + { + /** @var PhpDocInfo|null $phpDocInfo */ + $phpDocInfo = $property->getAttribute(AttributeKey::PHP_DOC_INFO); + if ($phpDocInfo === null) { + return null; + } + + return $phpDocInfo->getByType(ManyToManyTagValueNode::class); + } + + public function matchDoctrineManyToOneTagValueNode(Property $property): ?ManyToOneTagValueNode + { + /** @var PhpDocInfo|null $phpDocInfo */ + $phpDocInfo = $property->getAttribute(AttributeKey::PHP_DOC_INFO); + if ($phpDocInfo === null) { + return null; + } + + return $phpDocInfo->getByType(ManyToOneTagValueNode::class); + } + + public function matchDoctrineJoinColumnTagValueNode(Property $property): ?JoinColumnTagValueNode + { + /** @var PhpDocInfo|null $phpDocInfo */ + $phpDocInfo = $property->getAttribute(AttributeKey::PHP_DOC_INFO); + if ($phpDocInfo === null) { + return null; + } + + return $phpDocInfo->getByType(JoinColumnTagValueNode::class); + } + + public function matchDoctrineGeneratedValueTagValueNode(Property $property): ?GeneratedValueTagValueNode + { + /** @var PhpDocInfo|null $phpDocInfo */ + $phpDocInfo = $property->getAttribute(AttributeKey::PHP_DOC_INFO); + if ($phpDocInfo === null) { + return null; + } + + return $phpDocInfo->getByType(GeneratedValueTagValueNode::class); + } } diff --git a/rules/doctrine-code-quality/src/NodeManipulator/DoctrineItemDefaultValueManipulator.php b/rules/doctrine-code-quality/src/NodeManipulator/DoctrineItemDefaultValueManipulator.php new file mode 100644 index 00000000000..0a978d35e59 --- /dev/null +++ b/rules/doctrine-code-quality/src/NodeManipulator/DoctrineItemDefaultValueManipulator.php @@ -0,0 +1,53 @@ +hasItemWithDefaultValue($doctrineTagValueNode, $item, $defaultValue)) { + return; + } + + $this->hasModifiedAnnotation = true; + $doctrineTagValueNode->removeItem($item); + } + + /** + * @param string|bool|int $defaultValue + */ + private function hasItemWithDefaultValue( + AbstractDoctrineTagValueNode $doctrineTagValueNode, + string $item, + $defaultValue + ): bool { + $attributableItems = $doctrineTagValueNode->getAttributableItems(); + if (! isset($attributableItems[$item])) { + return false; + } + + return $attributableItems[$item] === $defaultValue; + } + + public function resetHasModifiedAnnotation(): void + { + $this->hasModifiedAnnotation = false; + } + + public function hasModifiedAnnotation(): bool + { + return $this->hasModifiedAnnotation; + } +} diff --git a/rules/doctrine-code-quality/src/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector.php b/rules/doctrine-code-quality/src/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector.php new file mode 100644 index 00000000000..ff2e8213404 --- /dev/null +++ b/rules/doctrine-code-quality/src/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector.php @@ -0,0 +1,107 @@ +doctrineClassAnalyzer = $doctrineClassAnalyzer; + $this->doctrineItemDefaultValueManipulator = $doctrineItemDefaultValueManipulator; + + } + + public function getDefinition(): RectorDefinition + { + return new RectorDefinition( + 'Removes redundant default values from Doctrine ORM annotations on class level', + [ + new CodeSample( + <<<'CODE_SAMPLE' +use Doctrine\ORM\Mapping as ORM; + +/** + * @ORM\Entity(readOnly=false) + */ +class SomeClass +{ +} +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +use Doctrine\ORM\Mapping as ORM; + +/** + * @ORM\Entity() + */ +class SomeClass +{ +} +CODE_SAMPLE + ), + ] + ); + } + + /** + * @return string[] + */ + public function getNodeTypes(): array + { + return [Class_::class]; + } + + public function refactor(Node $node): ?Node + { + $this->doctrineItemDefaultValueManipulator->resetHasModifiedAnnotation(); + if ($node instanceof Class_) { + $this->refactorClassAnnotations($node); + } + + if (! $this->doctrineItemDefaultValueManipulator->hasModifiedAnnotation()) { + return null; + } + + return $node; + } + + private function refactorClassAnnotations(Class_ $node): void + { + $this->refactorEntityAnnotation($node); + } + + private function refactorEntityAnnotation(Class_ $node): void + { + $entityTagValueNode = $this->doctrineClassAnalyzer->matchDoctrineEntityTagValueNode($node); + if ($entityTagValueNode === null) { + return; + } + + $this->doctrineItemDefaultValueManipulator->remove($entityTagValueNode, 'readOnly', false); + } +} diff --git a/rules/doctrine-code-quality/src/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector.php b/rules/doctrine-code-quality/src/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector.php new file mode 100644 index 00000000000..3cafb17bc17 --- /dev/null +++ b/rules/doctrine-code-quality/src/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector.php @@ -0,0 +1,191 @@ +doctrinePropertyAnalyzer = $doctrinePropertyAnalyzer; + $this->doctrineItemDefaultValueManipulator = $doctrineItemDefaultValueManipulator; + + } + + public function getDefinition(): RectorDefinition + { + return new RectorDefinition( + 'Removes redundant default values from Doctrine ORM annotations on class property level', + [ + new CodeSample( + <<<'CODE_SAMPLE' +use Doctrine\ORM\Mapping as ORM; + +/** + * @ORM\Entity + */ +class SomeClass +{ + /** + * @ORM\ManyToOne(targetEntity=Training::class) + * @ORM\JoinColumn(name="training", unique=false) + */ + private $training; +} +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +use Doctrine\ORM\Mapping as ORM; + +/** + * @ORM\Entity + */ +class SomeClass +{ + /** + * @ORM\ManyToOne(targetEntity=Training::class) + * @ORM\JoinColumn(name="training") + */ + private $training; +} +CODE_SAMPLE + ), + ] + ); + } + + /** + * @return string[] + */ + public function getNodeTypes(): array + { + return [Property::class]; + } + + public function refactor(Node $node): ?Node + { + $this->doctrineItemDefaultValueManipulator->resetHasModifiedAnnotation(); + if ($node instanceof Property) { + $this->refactorPropertyAnnotations($node); + } + + if (! $this->doctrineItemDefaultValueManipulator->hasModifiedAnnotation()) { + return null; + } + + return $node; + } + + private function refactorPropertyAnnotations(Property $node): void + { + $this->refactorColumnAnnotation($node); + $this->refactorGeneratedValueAnnotation($node); + $this->refactorJoinColumnAnnotation($node); + $this->refactorManyToManyAnnotation($node); + $this->refactorManyToOneAnnotation($node); + $this->refactorOneToManyAnnotation($node); + $this->refactorOneToOneAnnotation($node); + } + + private function refactorColumnAnnotation(Property $node): void + { + $columnTagValueNode = $this->doctrinePropertyAnalyzer->matchDoctrineColumnTagValueNode($node); + if ($columnTagValueNode === null) { + return; + } + + $this->doctrineItemDefaultValueManipulator->remove($columnTagValueNode, 'nullable', false); + $this->doctrineItemDefaultValueManipulator->remove($columnTagValueNode, 'unique', false); + $this->doctrineItemDefaultValueManipulator->remove($columnTagValueNode, 'precision', 0); + $this->doctrineItemDefaultValueManipulator->remove($columnTagValueNode, 'scale', 0); + } + + private function refactorJoinColumnAnnotation(Property $node): void + { + $joinColumnTagValueNode = $this->doctrinePropertyAnalyzer->matchDoctrineJoinColumnTagValueNode($node); + if ($joinColumnTagValueNode === null) { + return; + } + + $this->doctrineItemDefaultValueManipulator->remove($joinColumnTagValueNode, 'nullable', true); + $this->doctrineItemDefaultValueManipulator->remove($joinColumnTagValueNode, 'referencedColumnName', 'id'); + $this->doctrineItemDefaultValueManipulator->remove($joinColumnTagValueNode, 'unique', false); + } + + private function refactorGeneratedValueAnnotation(Property $node): void + { + $generatedValue = $this->doctrinePropertyAnalyzer->matchDoctrineGeneratedValueTagValueNode($node); + if ($generatedValue === null) { + return; + } + + $this->doctrineItemDefaultValueManipulator->remove($generatedValue, 'strategy', 'AUTO'); + } + + private function refactorManyToManyAnnotation(Property $node): void + { + $manyToManyTagValueNode = $this->doctrinePropertyAnalyzer->matchDoctrineManyToManyTagValueNode($node); + if ($manyToManyTagValueNode === null) { + return; + } + + $this->doctrineItemDefaultValueManipulator->remove($manyToManyTagValueNode, 'orphanRemoval', false); + $this->doctrineItemDefaultValueManipulator->remove($manyToManyTagValueNode, 'fetch', 'LAZY'); + } + + private function refactorManyToOneAnnotation(Property $node): void + { + $manyToOneTagValueNode = $this->doctrinePropertyAnalyzer->matchDoctrineManyToOneTagValueNode($node); + if ($manyToOneTagValueNode === null) { + return; + } + + $this->doctrineItemDefaultValueManipulator->remove($manyToOneTagValueNode, 'fetch', 'LAZY'); + } + + private function refactorOneToManyAnnotation(Property $node): void + { + $oneToManyTagValueNode = $this->doctrinePropertyAnalyzer->matchDoctrineOneToManyTagValueNode($node); + if ($oneToManyTagValueNode === null) { + return; + } + + $this->doctrineItemDefaultValueManipulator->remove($oneToManyTagValueNode, 'orphanRemoval', false); + $this->doctrineItemDefaultValueManipulator->remove($oneToManyTagValueNode, 'fetch', 'LAZY'); + } + + private function refactorOneToOneAnnotation(Property $node): void + { + $oneToManyTagValueNode = $this->doctrinePropertyAnalyzer->matchDoctrineOneToOneTagValueNode($node); + if ($oneToManyTagValueNode === null) { + return; + } + + $this->doctrineItemDefaultValueManipulator->remove($oneToManyTagValueNode, 'orphanRemoval', false); + $this->doctrineItemDefaultValueManipulator->remove($oneToManyTagValueNode, 'fetch', 'LAZY'); + } +} diff --git a/rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/Fixture/Entity/read_only_false.php.inc b/rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/Fixture/Entity/read_only_false.php.inc new file mode 100644 index 00000000000..cc3c8bc7d0c --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/Fixture/Entity/read_only_false.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/Fixture/Entity/read_only_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/Fixture/Entity/read_only_skipped.php.inc new file mode 100644 index 00000000000..d67319bcae2 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/Fixture/Entity/read_only_skipped.php.inc @@ -0,0 +1,14 @@ + diff --git a/rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/RemoveRedundantDefaultClassAnnotationValuesRectorTest.php b/rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/RemoveRedundantDefaultClassAnnotationValuesRectorTest.php new file mode 100644 index 00000000000..1a4e8037591 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector/RemoveRedundantDefaultClassAnnotationValuesRectorTest.php @@ -0,0 +1,31 @@ +doTestFileInfo($fileInfo); + } + + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return RemoveRedundantDefaultClassAnnotationValuesRector::class; + } +} diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/nullable_false.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/nullable_false.php.inc new file mode 100644 index 00000000000..2c47f010864 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/nullable_false.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/nullable_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/nullable_skipped.php.inc new file mode 100644 index 00000000000..208c43a6d51 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/nullable_skipped.php.inc @@ -0,0 +1,20 @@ + + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/precision_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/precision_skipped.php.inc new file mode 100644 index 00000000000..c8e87c342b9 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/precision_skipped.php.inc @@ -0,0 +1,19 @@ + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/precision_zero.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/precision_zero.php.inc new file mode 100644 index 00000000000..a3788026ba1 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/precision_zero.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/scale_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/scale_skipped.php.inc new file mode 100644 index 00000000000..48ac8e256d2 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/scale_skipped.php.inc @@ -0,0 +1,19 @@ + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/scale_zero.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/scale_zero.php.inc new file mode 100644 index 00000000000..0bca8fc9e83 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/scale_zero.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/unique_false.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/unique_false.php.inc new file mode 100644 index 00000000000..50bf3261a15 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/unique_false.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/unique_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/unique_skipped.php.inc new file mode 100644 index 00000000000..511863d432e --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/Column/unique_skipped.php.inc @@ -0,0 +1,19 @@ + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/GeneratedValue/strategy_auto.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/GeneratedValue/strategy_auto.php.inc new file mode 100644 index 00000000000..362e682fd07 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/GeneratedValue/strategy_auto.php.inc @@ -0,0 +1,43 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/GeneratedValue/strategy_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/GeneratedValue/strategy_skipped.php.inc new file mode 100644 index 00000000000..d55c7ca622d --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/GeneratedValue/strategy_skipped.php.inc @@ -0,0 +1,21 @@ + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/nullable_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/nullable_skipped.php.inc new file mode 100644 index 00000000000..42ddd1ea773 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/nullable_skipped.php.inc @@ -0,0 +1,21 @@ + + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/nullable_true.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/nullable_true.php.inc new file mode 100644 index 00000000000..f7287354e24 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/nullable_true.php.inc @@ -0,0 +1,41 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/referenced_column_name_id.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/referenced_column_name_id.php.inc new file mode 100644 index 00000000000..a08519c95bb --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/referenced_column_name_id.php.inc @@ -0,0 +1,41 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/referenced_column_name_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/referenced_column_name_skipped.php.inc new file mode 100644 index 00000000000..e72675b0f2a --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/referenced_column_name_skipped.php.inc @@ -0,0 +1,20 @@ + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/unique_false.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/unique_false.php.inc new file mode 100644 index 00000000000..571eb1641c5 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/unique_false.php.inc @@ -0,0 +1,41 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/unique_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/unique_skipped.php.inc new file mode 100644 index 00000000000..a107d67ef73 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/JoinColumn/unique_skipped.php.inc @@ -0,0 +1,20 @@ + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/fetch_lazy.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/fetch_lazy.php.inc new file mode 100644 index 00000000000..5d0bb4554a3 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/fetch_lazy.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/fetch_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/fetch_skipped.php.inc new file mode 100644 index 00000000000..0b813534c68 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/fetch_skipped.php.inc @@ -0,0 +1,20 @@ + + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/orphan_removal_false.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/orphan_removal_false.php.inc new file mode 100644 index 00000000000..404645b4115 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/orphan_removal_false.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/orphan_removal_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/orphan_removal_skipped.php.inc new file mode 100644 index 00000000000..788db72563c --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToMany/orphan_removal_skipped.php.inc @@ -0,0 +1,20 @@ + + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToOne/fetch_lazy.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToOne/fetch_lazy.php.inc new file mode 100644 index 00000000000..8b4deba4f4e --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToOne/fetch_lazy.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToOne/fetch_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToOne/fetch_skipped.php.inc new file mode 100644 index 00000000000..8af65100cb0 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/ManyToOne/fetch_skipped.php.inc @@ -0,0 +1,20 @@ + + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/fetch_lazy.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/fetch_lazy.php.inc new file mode 100644 index 00000000000..2d02e6e3121 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/fetch_lazy.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/fetch_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/fetch_skipped.php.inc new file mode 100644 index 00000000000..bc9a6697d3a --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/fetch_skipped.php.inc @@ -0,0 +1,20 @@ + + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/orphan_removal_false.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/orphan_removal_false.php.inc new file mode 100644 index 00000000000..4abff4fb830 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/orphan_removal_false.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/orphan_removal_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/orphan_removal_skipped.php.inc new file mode 100644 index 00000000000..3300f7d2d76 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToMany/orphan_removal_skipped.php.inc @@ -0,0 +1,20 @@ + + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/fetch_lazy.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/fetch_lazy.php.inc new file mode 100644 index 00000000000..bac7ab872c7 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/fetch_lazy.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/fetch_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/fetch_skipped.php.inc new file mode 100644 index 00000000000..97bea410912 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/fetch_skipped.php.inc @@ -0,0 +1,20 @@ + + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/orphan_removal_false.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/orphan_removal_false.php.inc new file mode 100644 index 00000000000..b214335f415 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/orphan_removal_false.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/orphan_removal_skipped.php.inc b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/orphan_removal_skipped.php.inc new file mode 100644 index 00000000000..20d39a4ebca --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Fixture/OneToOne/orphan_removal_skipped.php.inc @@ -0,0 +1,20 @@ + + diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/RemoveRedundantDefaultPropertyAnnotationValuesRectorTest.php b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/RemoveRedundantDefaultPropertyAnnotationValuesRectorTest.php new file mode 100644 index 00000000000..986b0ea81f0 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/RemoveRedundantDefaultPropertyAnnotationValuesRectorTest.php @@ -0,0 +1,31 @@ +doTestFileInfo($fileInfo); + } + + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return RemoveRedundantDefaultPropertyAnnotationValuesRector::class; + } +} diff --git a/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Source/Training.php b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Source/Training.php new file mode 100644 index 00000000000..ba11feff178 --- /dev/null +++ b/rules/doctrine-code-quality/tests/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector/Source/Training.php @@ -0,0 +1,10 @@ +