diff --git a/rules/Removing/Rector/Class_/RemoveInterfacesRector.php b/rules/Removing/Rector/Class_/RemoveInterfacesRector.php index 7dc3bd63c88..419bd6ffdfd 100644 --- a/rules/Removing/Rector/Class_/RemoveInterfacesRector.php +++ b/rules/Removing/Rector/Class_/RemoveInterfacesRector.php @@ -5,6 +5,7 @@ namespace Rector\Removing\Rector\Class_; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\Interface_; use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; @@ -38,27 +39,17 @@ CODE_SAMPLE */ public function getNodeTypes() : array { - return [Class_::class]; + return [Class_::class, Interface_::class]; } /** - * @param Class_ $node + * @param Class_|Interface_ $node */ public function refactor(Node $node) : ?Node { - if ($node->implements === []) { - return null; + if ($node instanceof Class_) { + return $this->refactorClass($node); } - $isInterfacesRemoved = \false; - foreach ($node->implements as $key => $implement) { - if ($this->isNames($implement, $this->interfacesToRemove)) { - unset($node->implements[$key]); - $isInterfacesRemoved = \true; - } - } - if (!$isInterfacesRemoved) { - return null; - } - return $node; + return $this->refactorInterface($node); } /** * @param mixed[] $configuration @@ -69,4 +60,36 @@ CODE_SAMPLE /** @var string[] $configuration */ $this->interfacesToRemove = $configuration; } + private function refactorClass(Class_ $class) : ?Class_ + { + if ($class->implements === []) { + return null; + } + $isInterfacesRemoved = \false; + foreach ($class->implements as $key => $implement) { + if ($this->isNames($implement, $this->interfacesToRemove)) { + unset($class->implements[$key]); + $isInterfacesRemoved = \true; + } + } + if (!$isInterfacesRemoved) { + return null; + } + return $class; + } + private function refactorInterface(Interface_ $interface) : ?\PhpParser\Node\Stmt\Interface_ + { + $isInterfacesRemoved = \false; + foreach ($interface->extends as $key => $extend) { + if (!$this->isNames($extend, $this->interfacesToRemove)) { + continue; + } + unset($interface->extends[$key]); + $isInterfacesRemoved = \true; + } + if (!$isInterfacesRemoved) { + return null; + } + return $interface; + } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 827d488ffe9..337f5c0ae37 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '0ba27d165c5ea7fcd0faa3eace142030c2ae3d18'; + public const PACKAGE_VERSION = '7ec3ae3514546043861ab1615509c6c8ab9c26ff'; /** * @api * @var string */ - public const RELEASE_DATE = '2025-01-19 00:33:52'; + public const RELEASE_DATE = '2025-01-19 08:19:55'; /** * @var int */