mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-30 06:33:31 +00:00
Use MethodNameChanger in ClassConstantReplacerRector
This commit is contained in:
parent
54ca59f59f
commit
3893d6618a
|
@ -6,6 +6,7 @@ use PhpParser\Node;
|
||||||
use PhpParser\Node\Expr\ClassConstFetch;
|
use PhpParser\Node\Expr\ClassConstFetch;
|
||||||
use PhpParser\Node\Identifier;
|
use PhpParser\Node\Identifier;
|
||||||
use Rector\NodeAnalyzer\ClassConstAnalyzer;
|
use Rector\NodeAnalyzer\ClassConstAnalyzer;
|
||||||
|
use Rector\NodeChanger\MethodNameChanger;
|
||||||
use Rector\Rector\AbstractRector;
|
use Rector\Rector\AbstractRector;
|
||||||
|
|
||||||
final class ClassConstantReplacerRector extends AbstractRector
|
final class ClassConstantReplacerRector extends AbstractRector
|
||||||
|
@ -24,6 +25,11 @@ final class ClassConstantReplacerRector extends AbstractRector
|
||||||
*/
|
*/
|
||||||
private $classConstAnalyzer;
|
private $classConstAnalyzer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var MethodNameChanger
|
||||||
|
*/
|
||||||
|
private $methodNameChanger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string|null
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
|
@ -32,10 +38,11 @@ final class ClassConstantReplacerRector extends AbstractRector
|
||||||
/**
|
/**
|
||||||
* @param string[] $oldToNewConstantsByClass
|
* @param string[] $oldToNewConstantsByClass
|
||||||
*/
|
*/
|
||||||
public function __construct(array $oldToNewConstantsByClass, ClassConstAnalyzer $classConstAnalyzer)
|
public function __construct(array $oldToNewConstantsByClass, ClassConstAnalyzer $classConstAnalyzer, MethodNameChanger $methodNameChanger)
|
||||||
{
|
{
|
||||||
$this->oldToNewConstantsByClass = $oldToNewConstantsByClass;
|
$this->oldToNewConstantsByClass = $oldToNewConstantsByClass;
|
||||||
$this->classConstAnalyzer = $classConstAnalyzer;
|
$this->classConstAnalyzer = $classConstAnalyzer;
|
||||||
|
$this->methodNameChanger = $methodNameChanger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isCandidate(Node $node): bool
|
public function isCandidate(Node $node): bool
|
||||||
|
@ -66,15 +73,13 @@ final class ClassConstantReplacerRector extends AbstractRector
|
||||||
|
|
||||||
$constantName = $identifierNode->toString();
|
$constantName = $identifierNode->toString();
|
||||||
|
|
||||||
if (! isset($configuration[$constantName])) {
|
$newConstantName = $configuration[$constantName];
|
||||||
|
|
||||||
|
if (! isset($newConstantName)) {
|
||||||
return $classConstFetchNode;
|
return $classConstFetchNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
$newConstantName = $configuration[$constantName];
|
return $this->methodNameChanger->renameNode($classConstFetchNode, $newConstantName);
|
||||||
|
|
||||||
$classConstFetchNode->name = new Identifier($newConstantName);
|
|
||||||
|
|
||||||
return $classConstFetchNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user