mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-19 17:42:23 +00:00
make use of isFuncCallName() method
This commit is contained in:
parent
83eca131e9
commit
fe86fc4365
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user