[Rector] HtmlAddMethodRector init

This commit is contained in:
TomasVotruba 2017-08-15 08:37:36 +02:00
parent 412c1f10b5
commit 7fe31cde23
4 changed files with 80 additions and 0 deletions

View 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;
}
}

View 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'
);
}
}

View File

@ -0,0 +1,3 @@
<?php declare (strict_types=1);
Nette\Utils\Html::addHtml('someContent');

View File

@ -0,0 +1,3 @@
<?php declare (strict_types=1);
Nette\Utils\Html::add('someContent');