From 0745a50ef39d734e911d17fd6c1e11a4e7c7e6ce Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 22 Oct 2026 13:20:42 +0200 Subject: [PATCH 1/2] [Transform] Deprecate MergeInterfacesRector as niche, context-dependent and never used --- .../Fixture/fixture.php.inc | 27 -------- .../Fixture/fixture2.php.inc | 25 ------- .../Fixture/fqcn.php.inc | 23 ------- .../MergeInterfacesRectorTest.php | 28 -------- .../Source/SomeInterface.php | 9 --- .../Source/SomeOldInterface.php | 9 --- .../config/configured_rule.php | 16 ----- .../Rector/Class_/MergeInterfacesRector.php | 69 +++---------------- 8 files changed, 8 insertions(+), 198 deletions(-) delete mode 100644 rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fixture.php.inc delete mode 100644 rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fixture2.php.inc delete mode 100644 rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fqcn.php.inc delete mode 100644 rules-tests/Transform/Rector/Class_/MergeInterfacesRector/MergeInterfacesRectorTest.php delete mode 100644 rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Source/SomeInterface.php delete mode 100644 rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Source/SomeOldInterface.php delete mode 100644 rules-tests/Transform/Rector/Class_/MergeInterfacesRector/config/configured_rule.php diff --git a/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fixture.php.inc b/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fixture.php.inc deleted file mode 100644 index f2cd7172e04..00000000000 --- a/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,27 +0,0 @@ - ------ - diff --git a/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fixture2.php.inc b/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fixture2.php.inc deleted file mode 100644 index 61d51360768..00000000000 --- a/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fixture2.php.inc +++ /dev/null @@ -1,25 +0,0 @@ - ------ - diff --git a/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fqcn.php.inc b/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fqcn.php.inc deleted file mode 100644 index 757cfeda779..00000000000 --- a/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Fixture/fqcn.php.inc +++ /dev/null @@ -1,23 +0,0 @@ - ------ - \ No newline at end of file diff --git a/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/MergeInterfacesRectorTest.php b/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/MergeInterfacesRectorTest.php deleted file mode 100644 index 14851c2b07a..00000000000 --- a/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/MergeInterfacesRectorTest.php +++ /dev/null @@ -1,28 +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/Transform/Rector/Class_/MergeInterfacesRector/Source/SomeInterface.php b/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Source/SomeInterface.php deleted file mode 100644 index a0443ca76b4..00000000000 --- a/rules-tests/Transform/Rector/Class_/MergeInterfacesRector/Source/SomeInterface.php +++ /dev/null @@ -1,9 +0,0 @@ -ruleWithConfiguration(MergeInterfacesRector::class, [ - SomeOldInterface::class => SomeInterface::class, - 'App\Interfaces\SomeInterface' => 'App\Interfaces\SomeOtherInterface', - ]); -}; diff --git a/rules/Transform/Rector/Class_/MergeInterfacesRector.php b/rules/Transform/Rector/Class_/MergeInterfacesRector.php index 998d39576f6..f2742877153 100644 --- a/rules/Transform/Rector/Class_/MergeInterfacesRector.php +++ b/rules/Transform/Rector/Class_/MergeInterfacesRector.php @@ -5,29 +5,19 @@ namespace Rector\Transform\Rector\Class_; use PhpParser\Node; -use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\Interface_; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; use Rector\Contract\Rector\ConfigurableRectorInterface; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\ConfiguredCodeSample; use Rector\RuleDoc\RuleDefinition; -use Webmozart\Assert\Assert; /** - * Covers cases like - * - https://github.com/FriendsOfPHP/PHP-CS-Fixer/commit/a1cdb4d2dd8f45d731244eed406e1d537218cc66 - * - https://github.com/FriendsOfPHP/PHP-CS-Fixer/commit/614d2e6f7af5a5b0be5363ff536aed2b7ee5a31d - * - * @see \Rector\Tests\Transform\Rector\Class_\MergeInterfacesRector\MergeInterfacesRectorTest + * @deprecated This rule is deprecated, as too niche and never used. Merging interfaces depends on project-specific context and is safer handled by a custom rule scoped to your exact case. */ -final class MergeInterfacesRector extends AbstractRector implements ConfigurableRectorInterface +final class MergeInterfacesRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface { - /** - * @var array - */ - private array $oldToNewInterfaces = []; - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Merge old interface to a new one, that already has its methods', [ @@ -59,34 +49,12 @@ public function getNodeTypes(): array return [Class_::class]; } - /** - * @param Class_ $node - */ public function refactor(Node $node): ?Node { - if ($node->implements === []) { - return null; - } - - $hasChanged = false; - foreach ($node->implements as $key => $implement) { - $oldInterfaces = array_keys($this->oldToNewInterfaces); - if (! $this->isNames($implement, $oldInterfaces)) { - continue; - } - - $interface = $this->getName($implement); - $node->implements[$key] = new FullyQualified($this->oldToNewInterfaces[$interface]); - $hasChanged = true; - } - - if (! $hasChanged) { - return null; - } - - $this->makeImplementsUnique($node); - - return $node; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as too niche and never used; use a custom rule scoped to your exact case instead', + self::class + )); } /** @@ -94,26 +62,5 @@ public function refactor(Node $node): ?Node */ public function configure(array $configuration): void { - Assert::allString(array_keys($configuration)); - Assert::allString($configuration); - - $this->oldToNewInterfaces = $configuration; - } - - private function makeImplementsUnique(Class_ $class): void - { - $alreadyAddedNames = []; - /** @var array $implements */ - $implements = $class->implements; - - foreach ($implements as $key => $name) { - $fqnName = $this->getName($name); - if (in_array($fqnName, $alreadyAddedNames, true)) { - unset($class->implements[$key]); - continue; - } - - $alreadyAddedNames[] = $fqnName; - } } } From 7d85693ccd99f57a0852aa82085b49fdf533666a Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 22 Oct 2026 11:21:38 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- rules/Transform/Rector/Class_/MergeInterfacesRector.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rules/Transform/Rector/Class_/MergeInterfacesRector.php b/rules/Transform/Rector/Class_/MergeInterfacesRector.php index f2742877153..a5e3b7d7708 100644 --- a/rules/Transform/Rector/Class_/MergeInterfacesRector.php +++ b/rules/Transform/Rector/Class_/MergeInterfacesRector.php @@ -49,6 +49,9 @@ public function getNodeTypes(): array return [Class_::class]; } + /** + * @param Class_ $node + */ public function refactor(Node $node): ?Node { throw new ShouldNotHappenException(sprintf(