From ca728d83546ceaf044d117727970e1a8f89ba11e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 7 Aug 2026 11:37:56 +0200 Subject: [PATCH] deprecate RemoveEmptyTableAttributeRector Removing an empty #[ORM\Table] has no effect on the mapping, so the rule only produces noise in the diff and can leave the reader wondering where the table mapping went. Keeping the explicit attribute is a valid style choice. --- config/sets/doctrine-code-quality.php | 3 -- .../fix_multiple_table_attributes.php.inc | 27 ----------- .../fix_single_table_attribute.php.inc | 26 ----------- .../Fixture/skip_done.php.inc | 10 ----- .../Fixture/skip_not_empty.php.inc | 11 ----- .../RemoveEmptyTableAttributeRectorTest.php | 28 ------------ .../config/configured_rule.php | 10 ----- .../RemoveEmptyTableAttributeRector.php | 45 ++++--------------- 8 files changed, 9 insertions(+), 151 deletions(-) delete mode 100644 rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/fix_multiple_table_attributes.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/fix_single_table_attribute.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/skip_done.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/skip_not_empty.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/RemoveEmptyTableAttributeRectorTest.php delete mode 100644 rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/config/configured_rule.php diff --git a/config/sets/doctrine-code-quality.php b/config/sets/doctrine-code-quality.php index 2416c90b..4b35d495 100644 --- a/config/sets/doctrine-code-quality.php +++ b/config/sets/doctrine-code-quality.php @@ -4,7 +4,6 @@ use Rector\Config\RectorConfig; use Rector\Doctrine\Bundle230\Rector\Class_\AddAnnotationToRepositoryRector; -use Rector\Doctrine\CodeQuality\Rector\Class_\RemoveEmptyTableAttributeRector; use Rector\Doctrine\CodeQuality\Rector\Property\CorrectDefaultTypesOnEntityPropertyRector; use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromColumnTypeRector; use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromToOneRelationTypeRector; @@ -16,8 +15,6 @@ $rectorConfig->rules([ CorrectDefaultTypesOnEntityPropertyRector::class, - RemoveEmptyTableAttributeRector::class, - // typed properties in entities from annotations/attributes TypedPropertyFromColumnTypeRector::class, TypedPropertyFromToOneRelationTypeRector::class, diff --git a/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/fix_multiple_table_attributes.php.inc b/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/fix_multiple_table_attributes.php.inc deleted file mode 100644 index 98273cbd..00000000 --- a/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/fix_multiple_table_attributes.php.inc +++ /dev/null @@ -1,27 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/fix_single_table_attribute.php.inc b/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/fix_single_table_attribute.php.inc deleted file mode 100644 index b3c6c6bd..00000000 --- a/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/fix_single_table_attribute.php.inc +++ /dev/null @@ -1,26 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/skip_done.php.inc b/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/skip_done.php.inc deleted file mode 100644 index c504f062..00000000 --- a/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/Fixture/skip_done.php.inc +++ /dev/null @@ -1,10 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/config/configured_rule.php b/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/config/configured_rule.php deleted file mode 100644 index 44c4f116..00000000 --- a/rules-tests/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(RemoveEmptyTableAttributeRector::class); -}; diff --git a/rules/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector.php b/rules/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector.php index 2c3911be..873c34ef 100644 --- a/rules/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector.php +++ b/rules/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector.php @@ -6,17 +6,17 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; -use Rector\Doctrine\Enum\MappingClass; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; -use Rector\ValueObject\PhpVersionFeature; -use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\Doctrine\Tests\CodeQuality\Rector\Class_\RemoveEmptyTableAttributeRector\RemoveEmptyTableAttributeRectorTest + * @deprecated as the removal has no effect on the mapping, while the missing attribute makes the entity harder to + * read. Keeping an explicit #[ORM\Table] is a valid style choice. */ -final class RemoveEmptyTableAttributeRector extends AbstractRector implements MinPhpVersionInterface +final class RemoveEmptyTableAttributeRector extends AbstractRector implements DeprecatedInterface { public function getRuleDefinition(): RuleDefinition { @@ -64,36 +64,9 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $hasChanged = false; - - foreach ($node->attrGroups as $attrGroupKey => $attrGroup) { - foreach ($attrGroup->attrs as $key => $attribute) { - if (! $this->isName($attribute, MappingClass::TABLE)) { - continue; - } - - if ($attribute->args !== []) { - continue; - } - - unset($attrGroup->attrs[$key]); - $hasChanged = true; - } - - if ($attrGroup->attrs === []) { - unset($node->attrGroups[$attrGroupKey]); - } - } - - if ($hasChanged) { - return $node; - } - - return null; - } - - public function provideMinPhpVersion(): int - { - return PhpVersionFeature::ATTRIBUTES; + throw new ShouldNotHappenException(sprintf( + '"%s" is deprecated and should not be used anymore. Remove it from your config files.', + self::class, + )); } }