mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-22 16:32:27 +02:00
[Rector] HtmlAddMethodRector init
This commit is contained in:
parent
412c1f10b5
commit
7fe31cde23
58
src/Rector/Contrib/Nette/HtmlAddMethodRector.php
Normal file
58
src/Rector/Contrib/Nette/HtmlAddMethodRector.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Rector\Contrib\Nette;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use Rector\Deprecation\SetNames;
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
||||
final class HtmlAddMethodRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var Node
|
||||
*/
|
||||
private $previousNode;
|
||||
|
||||
public function getSetName(): string
|
||||
{
|
||||
return SetNames::NETTE;
|
||||
}
|
||||
|
||||
public function sinceVersion(): float
|
||||
{
|
||||
return 2.4;
|
||||
}
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof StaticCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $node->name instanceof Identifier) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($node->class->getLast() !== 'Html') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((string) $node->name !== 'add') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StaticCall $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$node->name->name = 'addHtml';
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
16
tests/Rector/Contrib/Nette/HtmlAddMethodRector/Test.php
Normal file
16
tests/Rector/Contrib/Nette/HtmlAddMethodRector/Test.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Contrib\Nette\HtmlAddMethodRector;
|
||||
|
||||
use Rector\Testing\PHPUnit\AbstractReconstructorTestCase;
|
||||
|
||||
final class Test extends AbstractReconstructorTestCase
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/wrong/wrong.php.inc',
|
||||
__DIR__ . '/correct/correct.php.inc'
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
<?php declare (strict_types=1);
|
||||
|
||||
Nette\Utils\Html::addHtml('someContent');
|
@ -0,0 +1,3 @@
|
||||
<?php declare (strict_types=1);
|
||||
|
||||
Nette\Utils\Html::add('someContent');
|
Loading…
x
Reference in New Issue
Block a user