make use of isFuncCallName() method

This commit is contained in:
TomasVotruba 2020-03-01 00:06:45 +01:00
parent 83eca131e9
commit fe86fc4365
8 changed files with 16 additions and 18 deletions

View File

@ -7,7 +7,6 @@ namespace Rector\CakePHPToSymfony\Rector\Echo_;
use Nette\Utils\Html;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Stmt\Echo_;
@ -81,7 +80,7 @@ PHP
# e.g. |trans https://symfony.com/doc/current/translation/templates.html#using-twig-filters
$labelFilters = [];
if ($label instanceof FuncCall && $this->isName($label, '__')) {
if ($this->isFuncCallName($label, '__')) {
$labelFilters[] = 'trans';
$label = $label->args[0]->value;
}

View File

@ -9,7 +9,6 @@ use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
@ -57,7 +56,7 @@ final class SimplifyEmptyArrayCheckRector extends AbstractRector
$node,
// is_array(...)
function (Node $node): bool {
return $node instanceof FuncCall && $this->isName($node, 'is_array');
return $this->isFuncCallName($node, 'is_array');
},
Empty_::class
);

View File

@ -278,15 +278,6 @@ PHP
return false;
}
private function isFuncCallName(Expr $expr, string $name): bool
{
if (! $expr instanceof FuncCall) {
return false;
}
return $this->isName($expr, $name);
}
private function createForeach(For_ $for, string $iteratedVariableName): Foreach_
{
if ($this->iteratedExpr === null) {

View File

@ -64,7 +64,7 @@ final class SimplifyArraySearchRector extends AbstractRector
$matchedNodes = $this->binaryOpManipulator->matchFirstAndSecondConditionNode(
$node,
function (Node $node): bool {
return $node instanceof FuncCall && $this->isName($node, 'array_search');
return $this->isFuncCallName($node, 'array_search');
},
function (Node $node): bool {
return $this->isBool($node);

View File

@ -13,7 +13,6 @@ use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Cast\Bool_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Scalar\LNumber;
@ -113,7 +112,7 @@ PHP
private function resolveNewConditionNode(Expr $expr, bool $isNegated): ?BinaryOp
{
// various cases
if ($expr instanceof FuncCall && $this->isName($expr, 'count')) {
if ($this->isFuncCallName($expr, 'count')) {
return $this->resolveCount($isNegated, $expr);
}

View File

@ -74,7 +74,7 @@ PHP
}
$this->traverseNodesWithCallable($nextExpression, function (Node $node) use ($resultVariable): ?Variable {
if ($node instanceof FuncCall && $this->isName($node, 'get_defined_vars')) {
if ($this->isFuncCallName($node, 'get_defined_vars')) {
return $resultVariable;
}

View File

@ -173,7 +173,7 @@ PHP
private function isIteratorToArrayFuncCall(Expr $expr): bool
{
return $expr instanceof FuncCall && $this->isName($expr, 'iterator_to_array');
return $this->isFuncCallName($expr, 'iterator_to_array');
}
private function isConstantArrayTypeWithStringKeyType(Type $type): bool

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Rector\Core\Rector\AbstractRector;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use Rector\CodingStyle\Naming\ClassNaming;
@ -65,4 +66,13 @@ trait NameResolverTrait
{
return $this->classNaming->getShortName($name);
}
protected function isFuncCallName(Node $node, string $name): bool
{
if (! $node instanceof FuncCall) {
return false;
}
return $this->isName($node, $name);
}
}