Skip to content

Commit

Permalink
Updated Rector to commit 7ec3ae3514546043861ab1615509c6c8ab9c26ff
Browse files Browse the repository at this point in the history
rectorphp/rector-src@7ec3ae3 [removing] Add interface support to RemoveInterfaceRector (#6681)
  • Loading branch information
TomasVotruba committed Jan 19, 2025
1 parent 8a81a3e commit 6f5cf7f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
49 changes: 36 additions & 13 deletions rules/Removing/Rector/Class_/RemoveInterfacesRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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;
Expand Down Expand Up @@ -38,35 +39,57 @@ class SomeClass
*/
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 === []) {
if ($node instanceof Class_) {
return $this->refactorClass($node);
}
return $this->refactorInterface($node);
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
Assert::allString($configuration);
/** @var string[] $configuration */
$this->interfacesToRemove = $configuration;
}
private function refactorClass(Class_ $class) : ?Class_
{
if ($class->implements === []) {
return null;
}
$isInterfacesRemoved = \false;
foreach ($node->implements as $key => $implement) {
foreach ($class->implements as $key => $implement) {
if ($this->isNames($implement, $this->interfacesToRemove)) {
unset($node->implements[$key]);
unset($class->implements[$key]);
$isInterfacesRemoved = \true;
}
}
if (!$isInterfacesRemoved) {
return null;
}
return $node;
return $class;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
private function refactorInterface(Interface_ $interface) : ?\PhpParser\Node\Stmt\Interface_
{
Assert::allString($configuration);
/** @var string[] $configuration */
$this->interfacesToRemove = $configuration;
$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;
}
}
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 6f5cf7f

Please sign in to comment.