diff --git a/src/Rector/Contrib/Nette/HtmlAddMethodRector.php b/src/Rector/AbstractChangeMethodNameRector.php similarity index 62% rename from src/Rector/Contrib/Nette/HtmlAddMethodRector.php rename to src/Rector/AbstractChangeMethodNameRector.php index c61555f0e479..0a52dfa07f2b 100644 --- a/src/Rector/Contrib/Nette/HtmlAddMethodRector.php +++ b/src/Rector/AbstractChangeMethodNameRector.php @@ -1,36 +1,24 @@ isOnTypeCall($node, self::CLASS_NAME)) { + if ($this->isOnTypeCall($node, $this->getClassName())) { return true; } @@ -46,7 +34,7 @@ public function isCandidate(Node $node): bool */ public function refactor(Node $node): ?Node { - $node->name->name = 'addHtml'; + $node->name->name = $this->getNewMethodName(); return $node; } @@ -61,15 +49,11 @@ private function isStaticCall(Node $node): bool return false; } - if ($node->class->toString() !== self::CLASS_NAME) { - return false; - } - - if ((string) $node->name !== 'add') { + if ($node->class->toString() !== $this->getClassName()) { return false; } - return true; + return (string) $node->name === $this->getOldMethodName(); } private function isOnTypeCall(Node $node, string $class): bool diff --git a/src/Rector/Contrib/Nette/HtmlAddMethodRectorRector.php b/src/Rector/Contrib/Nette/HtmlAddMethodRectorRector.php new file mode 100644 index 000000000000..b7e0500e77c8 --- /dev/null +++ b/src/Rector/Contrib/Nette/HtmlAddMethodRectorRector.php @@ -0,0 +1,34 @@ +