mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 12:14:02 +01:00
move ValidateControlRector to Provider
This commit is contained in:
parent
1aadb0cee5
commit
d464401aae
@ -1,69 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Rector\Contrib\Nette\Application;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use Rector\Node\NodeFactory;
|
||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||
use Rector\NodeChanger\IdentifierRenamer;
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
||||
/**
|
||||
* Before::
|
||||
* - $myControl->validateControl(?$snippet)
|
||||
*
|
||||
* After:
|
||||
* - $myControl->redrawControl(?$snippet, false);
|
||||
*/
|
||||
final class ValidateControlRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var MethodCallAnalyzer
|
||||
*/
|
||||
private $methodCallAnalyzer;
|
||||
|
||||
/**
|
||||
* @var IdentifierRenamer
|
||||
*/
|
||||
private $identifierRenamer;
|
||||
|
||||
/**
|
||||
* @var NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
|
||||
public function __construct(
|
||||
MethodCallAnalyzer $methodCallAnalyzer,
|
||||
IdentifierRenamer $identifierRenamer,
|
||||
NodeFactory $nodeFactory
|
||||
) {
|
||||
$this->methodCallAnalyzer = $methodCallAnalyzer;
|
||||
$this->identifierRenamer = $identifierRenamer;
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
}
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
return $this->methodCallAnalyzer->isTypeAndMethod(
|
||||
$node,
|
||||
'Nette\Application\UI\Control',
|
||||
'validateControl'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MethodCall $methodCallNode
|
||||
*/
|
||||
public function refactor(Node $methodCallNode): Node
|
||||
{
|
||||
$this->identifierRenamer->renameNode($methodCallNode, 'redrawControl');
|
||||
|
||||
$methodCallNode->args[0] = $methodCallNode->args[0] ?? $this->nodeFactory->createArg(
|
||||
$this->nodeFactory->createNullConstant()
|
||||
);
|
||||
$methodCallNode->args[1] = $this->nodeFactory->createArg($this->nodeFactory->createFalseConstant());
|
||||
|
||||
return $methodCallNode;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Rector\Contrib\Nette\Application;
|
||||
|
||||
use Rector\Contract\Rector\RectorInterface;
|
||||
use Rector\RectorBuilder\BuilderRectorFactory;
|
||||
use Rector\RectorBuilder\Contract\RectorProviderInterface;
|
||||
|
||||
final class ValidateControlRectorProvider implements RectorProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var BuilderRectorFactory
|
||||
*/
|
||||
private $builderRectorFactory;
|
||||
|
||||
public function __construct(BuilderRectorFactory $builderRectorFactory)
|
||||
{
|
||||
$this->builderRectorFactory = $builderRectorFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Before::
|
||||
* - $myControl->validateControl(?$snippet)
|
||||
*
|
||||
* After:
|
||||
* - $myControl->redrawControl(?$snippet, false);
|
||||
*/
|
||||
public function provide(): RectorInterface
|
||||
{
|
||||
return $this->builderRectorFactory->create()
|
||||
->matchMethodCallByType('Nette\Application\UI\Control')
|
||||
->matchMethodName('validateControl')
|
||||
->changeMethodNameTo('redrawControl')
|
||||
->addArgument(1, false);
|
||||
}
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
|
||||
Rector\Rector\Contrib\Nette\Application\ValidateControlRectorProvider: ~
|
||||
|
||||
rectors:
|
||||
Rector\Rector\Contrib\Nette\Utils\NetteObjectToSmartTraitRector: ~
|
||||
Rector\Rector\Contrib\Nette\Utils\MagicMethodRector: ~
|
||||
|
||||
# application
|
||||
|
||||
# todo: turn to RectorProvider with fluent setup
|
||||
Rector\Rector\Contrib\Nette\Application\ValidateControlRector: ~
|
||||
|
||||
Rector\Rector\Contrib\Nette\Application\TemplateMagicInvokeFilterCallRector: ~
|
||||
Rector\Rector\Contrib\Nette\Application\TemplateRegisterHelperRector: ~
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user