mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-22 00:12:29 +02:00
[Nette] prepare type call for Html
This commit is contained in:
parent
75bf8dce4e
commit
70775f5bfa
@ -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?
|
||||
}
|
||||
}
|
||||
|
@ -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'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
<?php declare (strict_types=1);
|
||||
|
||||
$html = new \Nette\Utils\Html();
|
||||
$html->addHtml('someContent');
|
@ -0,0 +1,4 @@
|
||||
<?php declare (strict_types=1);
|
||||
|
||||
$html = new \Nette\Utils\Html();
|
||||
$html->add('someContent');
|
Loading…
x
Reference in New Issue
Block a user