[Nette] prepare type call for Html

This commit is contained in:
TomasVotruba 2017-08-15 15:24:56 +02:00
parent 75bf8dce4e
commit 70775f5bfa
4 changed files with 44 additions and 8 deletions

View File

@ -2,6 +2,7 @@
namespace Rector\Rector\Contrib\Nette;
use Nette\Utils\Html;
use PhpParser\Node;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
@ -21,6 +22,29 @@ final class HtmlAddMethodRector extends AbstractRector
}
public function isCandidate(Node $node): bool
{
if (! $this->isOnTypeCall($node, Html::class)) {
return false;
}
if (! $this->isStaticCall($node)) {
return false;
}
return true;
}
/**
* @param StaticCall $node
*/
public function refactor(Node $node): ?Node
{
$node->name->name = 'addHtml';
return $node;
}
private function isStaticCall(Node $node): bool
{
if (! $node instanceof StaticCall) {
return false;
@ -41,13 +65,13 @@ final class HtmlAddMethodRector extends AbstractRector
return true;
}
/**
* @param StaticCall $node
*/
public function refactor(Node $node): ?Node
private function isOnTypeCall(Node $node, string $class): bool
{
$node->name->name = 'addHtml';
dump($class);
die;
return $node;
# check elements type:
# inspire: https://github.com/phpstan/phpstan/blob/355060961eb4a33304c66dfbfc0cd32870a0b9d4/src/Rules/Methods/CallMethodsRule.php#L74
# local package?
}
}

View File

@ -9,9 +9,13 @@ final class Test extends AbstractRectorTestCase
{
public function test(): void
{
// $this->doTestFileMatchesExpectedContent(
// __DIR__ . '/wrong/wrong.php.inc',
// __DIR__ . '/correct/correct.php.inc'
// );
$this->doTestFileMatchesExpectedContent(
__DIR__ . '/wrong/wrong.php.inc',
__DIR__ . '/correct/correct.php.inc'
__DIR__ . '/wrong/wrong2.php.inc',
__DIR__ . '/correct/correct2.php.inc'
);
}

View File

@ -0,0 +1,4 @@
<?php declare (strict_types=1);
$html = new \Nette\Utils\Html();
$html->addHtml('someContent');

View File

@ -0,0 +1,4 @@
<?php declare (strict_types=1);
$html = new \Nette\Utils\Html();
$html->add('someContent');