mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-29 14:13:30 +00:00
cleanup
This commit is contained in:
parent
3e1eec178f
commit
ed7462b8a4
|
@ -1,41 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Rector;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
|
||||
abstract class AbstractClassReplacerRector extends AbstractRector
|
||||
{
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof Name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fqnName = $node->toString();
|
||||
|
||||
return isset($this->getOldToNewClasses()[$fqnName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Name $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$newName = $this->getNewName($node->toString());
|
||||
|
||||
return new FullyQualified($newName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
abstract protected function getOldToNewClasses(): array;
|
||||
|
||||
private function getNewName(string $oldName): string
|
||||
{
|
||||
return $this->getOldToNewClasses()[$oldName];
|
||||
}
|
||||
}
|
|
@ -2,10 +2,14 @@
|
|||
|
||||
namespace Rector\Rector\Dynamic;
|
||||
|
||||
use Rector\Rector\AbstractClassReplacerRector;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
||||
final class ClassReplacerRector extends AbstractClassReplacerRector
|
||||
final class ClassReplacerRector extends AbstractRector
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
|
@ -19,11 +23,32 @@ final class ClassReplacerRector extends AbstractClassReplacerRector
|
|||
$this->oldToNewClasses = $oldToNewClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getOldToNewClasses(): array
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
return $this->oldToNewClasses;
|
||||
if (! $node instanceof Name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fqnName = $node->toString();
|
||||
|
||||
return isset($this->oldToNewClasses[$fqnName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Name $nameNode
|
||||
*/
|
||||
public function refactor(Node $nameNode): ?Node
|
||||
{
|
||||
$newName = $this->getNewName($nameNode->toString());
|
||||
|
||||
// if already present use statement, just null it
|
||||
// ... neturn Nop()
|
||||
|
||||
return new FullyQualified($newName);
|
||||
}
|
||||
|
||||
private function getNewName(string $oldName): string
|
||||
{
|
||||
return $this->oldToNewClasses[$oldName];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user