[Nette] decouple instantiation to NodeFactory

This commit is contained in:
TomasVotruba 2017-09-05 23:32:23 +02:00
parent 2b5ce2b815
commit 767a5559af
2 changed files with 20 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -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()
);
}
}