opt
/
cpanel
/
ea-wappspector
/
vendor
/
rector
/
rector
/
rules
/
Removing
/
Rector
/
Class_
➕ New
📤 Upload
✎ Editing:
RemoveInterfacesRector.php
← Back
<?php declare (strict_types=1); namespace Rector\Removing\Rector\Class_; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use RectorPrefix202411\Webmozart\Assert\Assert; /** * @see \Rector\Tests\Removing\Rector\Class_\RemoveInterfacesRector\RemoveInterfacesRectorTest */ final class RemoveInterfacesRector extends AbstractRector implements ConfigurableRectorInterface { /** * @var string[] */ private $interfacesToRemove = []; public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Removes interfaces usage from class.', [new ConfiguredCodeSample(<<<'CODE_SAMPLE' class SomeClass implements SomeInterface { } CODE_SAMPLE , <<<'CODE_SAMPLE' class SomeClass { } CODE_SAMPLE , ['SomeInterface'])]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [Class_::class]; } /** * @param Class_ $node */ public function refactor(Node $node) : ?Node { if ($node->implements === []) { return null; } $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; } /** * @param mixed[] $configuration */ public function configure(array $configuration) : void { Assert::allString($configuration); /** @var string[] $configuration */ $this->interfacesToRemove = $configuration; } }
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel