mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-22 00:12:29 +02:00
fix ValueResoluver, add ClassConstFetchResolver
This commit is contained in:
parent
9a61cb23e9
commit
a35e715d3a
@ -0,0 +1,29 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeValueResolver\PerNodeValueResolver;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\NodeValueResolver\Contract\PerNodeValueResolver\PerNodeValueResolverInterface;
|
||||
|
||||
final class ClassConstFetchResolver implements PerNodeValueResolverInterface
|
||||
{
|
||||
public function getNodeClass(): string
|
||||
{
|
||||
return ClassConstFetch::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassConstFetch $classConstFetchNode
|
||||
*/
|
||||
public function resolve(Node $classConstFetchNode): string
|
||||
{
|
||||
$class = $classConstFetchNode->class->getAttribute(Attribute::RESOLVED_NAME)
|
||||
->toString();
|
||||
|
||||
$constant = $classConstFetchNode->name->toString();
|
||||
|
||||
return $class . '::' . $constant;
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Rector\Rector\Dynamic;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\BuilderHelpers;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
@ -10,10 +9,10 @@ use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
use Rector\NodeAnalyzer\ClassMethodAnalyzer;
|
||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||
use Rector\NodeAnalyzer\StaticMethodCallAnalyzer;
|
||||
use Rector\NodeValueResolver\NodeValueResolver;
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
||||
final class ArgumentReplacerRector extends AbstractRector
|
||||
@ -44,9 +43,9 @@ final class ArgumentReplacerRector extends AbstractRector
|
||||
private $staticMethodCallAnalyzer;
|
||||
|
||||
/**
|
||||
* @var Standard
|
||||
* @var NodeValueResolver
|
||||
*/
|
||||
private $standard;
|
||||
private $nodeValueResolver;
|
||||
|
||||
/**
|
||||
* @param mixed[] $argumentChangesByMethodAndType
|
||||
@ -56,13 +55,13 @@ final class ArgumentReplacerRector extends AbstractRector
|
||||
MethodCallAnalyzer $methodCallAnalyzer,
|
||||
ClassMethodAnalyzer $classMethodAnalyzer,
|
||||
StaticMethodCallAnalyzer $staticMethodCallAnalyzer,
|
||||
Standard $standard
|
||||
NodeValueResolver $nodeValueResolver
|
||||
) {
|
||||
$this->argumentChangesMethodAndClass = $argumentChangesByMethodAndType;
|
||||
$this->methodCallAnalyzer = $methodCallAnalyzer;
|
||||
$this->classMethodAnalyzer = $classMethodAnalyzer;
|
||||
$this->staticMethodCallAnalyzer = $staticMethodCallAnalyzer;
|
||||
$this->standard = $standard;
|
||||
$this->nodeValueResolver = $nodeValueResolver;
|
||||
}
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
@ -93,9 +92,9 @@ final class ArgumentReplacerRector extends AbstractRector
|
||||
// replace old value with new one
|
||||
$argumentsOrParameter = $argumentsOrParameters[$position];
|
||||
|
||||
// very dummy mechanism just for now
|
||||
$currentValue = $this->standard->prettyPrint([$argumentsOrParameter]);
|
||||
if (Strings::endsWith($key, $currentValue)) {
|
||||
$resolvedValue = $this->nodeValueResolver->resolve($argumentsOrParameter->value);
|
||||
|
||||
if ($resolvedValue === $key) {
|
||||
$argumentsOrParameters[$position] = BuilderHelpers::normalizeValue($value);
|
||||
}
|
||||
}
|
||||
|
@ -20,4 +20,4 @@ rectors:
|
||||
'setScope':
|
||||
0:
|
||||
# replace by new value
|
||||
'Symfony\Component\DependencyInjection\ContainerBuilder\ContainerBuilder::SCOPE_PROTOTYPE': false
|
||||
'Symfony\Component\DependencyInjection\ContainerBuilder::SCOPE_PROTOTYPE': false
|
||||
|
Loading…
x
Reference in New Issue
Block a user