This commit is contained in:
TomasVotruba 2017-09-05 21:30:15 +02:00
parent e3e26f8ccf
commit 2b5ce2b815
2 changed files with 21 additions and 17 deletions

View File

@ -8,6 +8,9 @@ use PhpParser\Node\Expr\StaticCall;
final class MethodCallAnalyzer
{
/**
* @param string[] $methodsNames
*/
public function isMethodCallTypeAndMethods(Node $node, string $type, array $methodsNames): bool
{
if (! $this->isMethodCallType($node, $type)) {
@ -17,21 +20,6 @@ final class MethodCallAnalyzer
return in_array((string) $node->name, $methodsNames, true);
}
private function isMethodCallType(Node $node, string $type): bool
{
if (! $node instanceof MethodCall) {
return false;
}
$variableType = $this->findVariableType($node);
if ($variableType !== $type) {
return false;
}
return true;
}
/**
* @param string[] $methodNames
*/
@ -53,6 +41,20 @@ final class MethodCallAnalyzer
return false;
}
private function isMethodCallType(Node $node, string $type): bool
{
if (! $node instanceof MethodCall) {
return false;
}
$variableType = $this->findVariableType($node);
if ($variableType !== $type) {
return false;
}
return true;
}
private function isStaticMethodCallType(Node $node, string $type): bool
{
if (! $node instanceof StaticCall) {

View File

@ -3,6 +3,8 @@
namespace Rector\Rector\Contrib\Nette;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\MethodCall;
use Rector\Deprecation\SetNames;
use Rector\NodeAnalyzer\MethodCallAnalyzer;
@ -57,7 +59,7 @@ final class FormSetRequiredRector extends AbstractRector
}
$arg = $node->args[0];
if (! $arg->value instanceof Node\Expr\ClassConstFetch) {
if (! $arg->value instanceof ClassConstFetch) {
return false;
}
@ -74,7 +76,7 @@ final class FormSetRequiredRector extends AbstractRector
public function refactor(Node $node): ?Node
{
$args = [
new Node\Arg($this->nodeFactory->createFalseConstant())
new Arg($this->nodeFactory->createFalseConstant()),
];
return new MethodCall($node->var, 'setRequired', $args);