From 6c83576acab4420b1634ef8968efbc8c9352a78b Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Tue, 26 Dec 2017 19:09:39 -0200 Subject: [PATCH] Use MethodNameChanger in AssertCompareToSpecificMethodRector --- .../AssertCompareToSpecificMethodRector.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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); } }