mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-24 17:29:45 +01:00
Updated Rector to commit 7ec3ae3514546043861ab1615509c6c8ab9c26ff
7ec3ae3514
[removing] Add interface support to RemoveInterfaceRector (#6681)
This commit is contained in:
parent
8a81a3ea16
commit
6f5cf7f6b4
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user