mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
[Nette] decouple instantiation to NodeFactory
This commit is contained in:
parent
2b5ce2b815
commit
767a5559af
@ -3,6 +3,8 @@
|
||||
namespace Rector\NodeFactory;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
@ -88,4 +90,17 @@ final class NodeFactory
|
||||
'kind' => Array_::KIND_SHORT,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $arguments
|
||||
*/
|
||||
public function createMethodCallWithVarAndArgs(Expr $expressionNode, string $methodName, ...$arguments): MethodCall
|
||||
{
|
||||
$args = [];
|
||||
foreach ($arguments as $argument) {
|
||||
$args[] = new Arg($argument);
|
||||
}
|
||||
|
||||
return new MethodCall($expressionNode, $methodName, $args);
|
||||
}
|
||||
}
|
||||
|
@ -75,10 +75,10 @@ final class FormSetRequiredRector extends AbstractRector
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$args = [
|
||||
new Arg($this->nodeFactory->createFalseConstant()),
|
||||
];
|
||||
|
||||
return new MethodCall($node->var, 'setRequired', $args);
|
||||
return $this->nodeFactory->createMethodCallWithVarAndArgs(
|
||||
$node->var,
|
||||
'setRequired',
|
||||
$this->nodeFactory->createFalseConstant()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user