diff --git a/src/Rector/Contrib/PHPUnit/SpecificMethod/AssertCompareToSpecificMethodRector.php b/src/Rector/Contrib/PHPUnit/SpecificMethod/AssertCompareToSpecificMethodRector.php index 6c4af5c18c2..7c063ac2aab 100644 --- a/src/Rector/Contrib/PHPUnit/SpecificMethod/AssertCompareToSpecificMethodRector.php +++ b/src/Rector/Contrib/PHPUnit/SpecificMethod/AssertCompareToSpecificMethodRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; use Rector\NodeAnalyzer\MethodCallAnalyzer; +use Rector\NodeChanger\MethodNameChanger; use Rector\Rector\AbstractRector; /** @@ -42,14 +43,20 @@ final class AssertCompareToSpecificMethodRector extends AbstractRector */ private $methodCallAnalyzer; + /** + * @var MethodNameChanger + */ + private $methodNameChanger; + /** * @var string|null */ private $activeFuncCallName; - public function __construct(MethodCallAnalyzer $methodCallAnalyzer) + public function __construct(MethodCallAnalyzer $methodCallAnalyzer, MethodNameChanger $methodNameChanger) { $this->methodCallAnalyzer = $methodCallAnalyzer; + $this->methodNameChanger = $methodNameChanger; } public function isCandidate(Node $node): bool @@ -109,11 +116,9 @@ final class AssertCompareToSpecificMethodRector extends AbstractRector [$trueMethodName, $falseMethodName] = $this->defaultOldToNewMethods[$this->activeFuncCallName]; if (in_array($oldMethodName, ['assertSame', 'assertEquals']) && $trueMethodName) { - /** @var string $trueMethodName */ - $methodCallNode->name = new Identifier($trueMethodName); + $this->methodNameChanger->renameNode($methodCallNode, $trueMethodName); } elseif (in_array($oldMethodName, ['assertNotSame', 'assertNotEquals']) && $falseMethodName) { - /** @var string $falseMethodName */ - $methodCallNode->name = new Identifier($falseMethodName); + $this->methodNameChanger->renameNode($methodCallNode, $falseMethodName); } }