Updated Rector to commit 17cfa9f376

17cfa9f376 Update to nikic/php-parser 4.13.0 (#904)
This commit is contained in:
Tomas Votruba 2021-09-27 15:43:15 +00:00
parent 8a7156a2a1
commit 73d7212e05
166 changed files with 2291 additions and 982 deletions

View File

@ -28,7 +28,8 @@ $autoloadIncluder->includeDependencyOrRepositoryVendorAutoloadIfExists();
$extractedPhpstanAutoload = __DIR__ . '/../vendor/phpstan/phpstan-extracted/vendor/autoload.php';
if (\file_exists($extractedPhpstanAutoload)) {
require_once $extractedPhpstanAutoload;
} elseif (\RectorPrefix20210927\should_include_preload()) {
}
if (\file_exists(__DIR__ . '/../preload.php')) {
require_once __DIR__ . '/../preload.php';
}
require_once __DIR__ . '/../src/constants.php';
@ -111,15 +112,3 @@ final class AutoloadIncluder
}
}
\class_alias('RectorPrefix20210927\\AutoloadIncluder', 'AutoloadIncluder', \false);
// load local php-parser only in prefixed version or development repository
function should_include_preload() : bool
{
if (\file_exists(__DIR__ . '/../vendor/scoper-autoload.php')) {
return \true;
}
if (!\file_exists(\getcwd() . '/composer.json')) {
return \false;
}
$composerJsonFileContent = \file_get_contents(\getcwd() . '/composer.json');
return \strpos($composerJsonFileContent, '"name": "rector/rector"') !== \false;
}

View File

@ -10,6 +10,7 @@ use PhpParser\Node\Expr\Variable;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\NodeNameResolver\NodeNameResolver;
@ -33,12 +34,17 @@ final class PregMatchTypeCorrector
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
*/
private $nodeComparator;
public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $betterNodeFinder, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\NodeNestingScope\ParentScopeFinder $parentScopeFinder, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $betterNodeFinder, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\NodeNestingScope\ParentScopeFinder $parentScopeFinder, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->betterNodeFinder = $betterNodeFinder;
$this->nodeNameResolver = $nodeNameResolver;
$this->parentScopeFinder = $parentScopeFinder;
$this->nodeComparator = $nodeComparator;
$this->argsAnalyzer = $argsAnalyzer;
}
/**
* Special case for "preg_match(), preg_match_all()" - with 3rd argument
@ -65,11 +71,13 @@ final class PregMatchTypeCorrector
if (!$this->nodeNameResolver->isNames($funcCallNode, ['preg_match', 'preg_match_all'])) {
continue;
}
if (!isset($funcCallNode->args[2])) {
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($funcCallNode->args, 2)) {
continue;
}
/** @var Arg $thirdArg */
$thirdArg = $funcCallNode->args[2];
// are the same variables
if (!$this->nodeComparator->areNodesEqual($funcCallNode->args[2]->value, $node)) {
if (!$this->nodeComparator->areNodesEqual($thirdArg->value, $node)) {
continue;
}
return new \PHPStan\Type\ArrayType(new \PHPStan\Type\MixedType(), new \PHPStan\Type\MixedType());

View File

@ -2,249 +2,254 @@
declare(strict_types=1);
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Comment.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Error.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Php5.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Tokens.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ConstExprEvaluator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NameContext.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Comment/Doc.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Eval_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/FuncCall.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/PreDec.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ClassConstFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseOr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseAnd.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Minus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseXor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Concat.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Div.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/ShiftRight.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/ShiftLeft.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Mod.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Mul.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Pow.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Plus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Coalesce.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/YieldFrom.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Error.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BitwiseNot.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/PostInc.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseOr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BooleanOr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseAnd.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Minus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseXor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Concat.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalOr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalXor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Spaceship.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Div.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/NotIdentical.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Greater.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalAnd.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/ShiftRight.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/ShiftLeft.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/GreaterOrEqual.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Equal.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Identical.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Mod.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BooleanAnd.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Mul.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/SmallerOrEqual.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Pow.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/NotEqual.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Plus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Smaller.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Coalesce.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Yield_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ErrorSuppress.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Instanceof_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Include_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/StaticCall.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ClosureUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Unset_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Array_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Object_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Bool_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Int_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Double.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/String_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/MethodCall.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/UnaryMinus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Array_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Variable.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Assign.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ConstFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/PreInc.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Exit_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Empty_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/PostDec.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Throw_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/NullsafePropertyFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/StaticPropertyFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignRef.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BooleanNot.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ShellExec.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Isset_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Match_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/PropertyFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/UnaryPlus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrowFunction.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Clone_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Closure.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Ternary.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/New_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/List_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayItem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayDimFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Print_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/NullsafeMethodCall.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Global_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ElseIf_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Expression.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/DeclareDeclare.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassConst.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Class_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Continue_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Enum_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Const_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Echo_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Switch_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Property.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Static_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Else_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Function_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/If_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Finally_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/For_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Trait_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Declare_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Nop.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Catch_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Unset_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Break_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassMethod.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Foreach_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Case_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Use_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Do_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/UseUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Label.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/GroupUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Throw_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/PropertyProperty.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/While_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/EnumCase.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/StaticVar.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Interface_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Goto_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassLike.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Return_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TryCatch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Namespace_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/InlineHTML.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/HaltCompiler.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Param.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Arg.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Const_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/LNumber.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Encapsed.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/EncapsedStringPart.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/String_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Class_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Function_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Trait_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Line.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/File.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Method.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Dir.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/NullableType.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/FunctionLike.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Attribute.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Name.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/AttributeGroup.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/UnionType.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/VarLikeIdentifier.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/MatchArm.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Name/Relative.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Name/FullyQualified.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Identifier.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/Emulative.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/KeywordEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NumericLiteralSeparatorEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/FlexibleDocStringEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/EnumTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/CoaleseEqualTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/JsonDecoder.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Declaration.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/ClassConst.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Param.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Class_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Property.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Function_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/FunctionLike.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Trait_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Method.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Use_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/TraitUseAdaptation.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Interface_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/TraitUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Namespace_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeTraverserInterface.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitorAbstract.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/Differ.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/PrintableNewAnonClassNode.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/DiffElem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/TokenStream.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ErrorHandler/Collecting.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ErrorHandler/Throwing.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FindingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/NameResolver.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/CloningVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FindingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ErrorHandler.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ConstExprEvaluationException.php';
require_once __DIR__ . '/vendor/symplify/symfony-php-config/src/Reflection/ArgumentAndParameterFactory.php';
require_once __DIR__ . '/vendor/symplify/symfony-php-config/src/Exception/ValueObjectException.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/Emulative.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/KeywordEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/EnumTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NumericLiteralSeparatorEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/FlexibleDocStringEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/CoaleseEqualTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Comment/Doc.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ConstExprEvaluator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/DiffElem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/Differ.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/PrintableNewAnonClassNode.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/TokenStream.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Tokens.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Php5.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ErrorHandler/Throwing.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ErrorHandler/Collecting.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/JsonDecoder.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Error.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Comment.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ErrorHandler.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/EnumCase.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Expression.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/UseUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Global_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Namespace_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Catch_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Class_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Throw_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/PropertyProperty.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Label.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/StaticVar.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Case_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Continue_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassMethod.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Unset_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Finally_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Interface_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Else_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/While_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/HaltCompiler.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/DeclareDeclare.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Goto_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Static_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Return_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TryCatch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Echo_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Declare_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Property.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Break_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/If_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Const_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Function_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Switch_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Foreach_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/For_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Do_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/GroupUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassLike.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Use_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/InlineHTML.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassConst.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ElseIf_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Nop.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Trait_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Enum_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/MatchArm.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/NullableType.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Identifier.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/ComplexType.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Param.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Attribute.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/List_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ShellExec.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ConstFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Include_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/StaticPropertyFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Variable.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Print_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/PreInc.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/StaticCall.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/YieldFrom.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Closure.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Int_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Object_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Double.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/String_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Unset_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Bool_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Array_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Throw_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/PostDec.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/UnaryMinus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ClassConstFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BitwiseNot.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ErrorSuppress.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrowFunction.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Eval_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/NullsafePropertyFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayDimFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/CallLike.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/MethodCall.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/PropertyFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Plus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/ShiftRight.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Div.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Mod.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseOr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Minus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Pow.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Mul.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Concat.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/ShiftLeft.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseXor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Coalesce.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseAnd.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Plus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Greater.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalOr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Spaceship.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Smaller.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/ShiftRight.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BooleanOr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalAnd.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Equal.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/NotIdentical.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/SmallerOrEqual.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BooleanAnd.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Div.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalXor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Mod.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseOr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Minus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Identical.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/GreaterOrEqual.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Pow.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Mul.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Concat.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/ShiftLeft.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseXor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Coalesce.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/NotEqual.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseAnd.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Assign.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/PostInc.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Error.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/UnaryPlus.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Ternary.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Empty_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/New_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Yield_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Exit_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/NullsafeMethodCall.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Instanceof_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/FuncCall.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/BooleanNot.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Clone_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/PreDec.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Match_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayItem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Array_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/AssignRef.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Isset_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ClosureUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/AttributeGroup.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/UnionType.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Const_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/FunctionLike.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/VariadicPlaceholder.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Name/Relative.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Name/FullyQualified.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/VarLikeIdentifier.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/IntersectionType.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Name.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/String_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Class_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Dir.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/File.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Method.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Function_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Line.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Trait_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/LNumber.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/EncapsedStringPart.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Encapsed.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Arg.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Namespace_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/TraitUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Class_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Param.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/TraitUseAdaptation.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Method.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Interface_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Property.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Declaration.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Function_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Use_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/FunctionLike.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/ClassConst.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Builder/Trait_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeTraverserInterface.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php';
require_once __DIR__ . '/vendor/symplify/symfony-php-config/src/ValueObjectInliner.php';
require_once __DIR__ . '/vendor/symplify/symfony-php-config/src/Exception/ValueObjectException.php';
require_once __DIR__ . '/vendor/symplify/symfony-php-config/src/Reflection/ArgumentAndParameterFactory.php';
require_once __DIR__ . '/vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php';

View File

@ -77,14 +77,17 @@ final class ArgumentDefaultValueReplacer
/**
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall $expr
*/
private function processArgs($expr, \Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue) : \PhpParser\Node\Expr
private function processArgs($expr, \Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue) : ?\PhpParser\Node\Expr
{
$position = $replaceArgumentDefaultValue->getPosition();
if (!$expr->args[$position] instanceof \PhpParser\Node\Arg) {
return null;
}
$argValue = $this->valueResolver->getValue($expr->args[$position]->value);
if (\is_scalar($replaceArgumentDefaultValue->getValueBefore()) && $argValue === $replaceArgumentDefaultValue->getValueBefore()) {
$expr->args[$position] = $this->normalizeValueToArgument($replaceArgumentDefaultValue->getValueAfter());
} elseif (\is_array($replaceArgumentDefaultValue->getValueBefore())) {
$newArgs = $this->processArrayReplacement($expr->args, $replaceArgumentDefaultValue);
$newArgs = $this->processArrayReplacement($expr->getArgs(), $replaceArgumentDefaultValue);
if ($newArgs) {
$expr->args = $newArgs;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Arguments\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use Rector\Arguments\ValueObject\SwapFuncCallArguments;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
@ -104,6 +105,9 @@ CODE_SAMPLE
if (!isset($funcCall->args[$newPosition])) {
continue;
}
if (!$funcCall->args[$oldPosition] instanceof \PhpParser\Node\Arg) {
continue;
}
$newArguments[$newPosition] = $funcCall->args[$oldPosition];
}
return $newArguments;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Carbon\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
@ -67,6 +68,9 @@ CODE_SAMPLE
if (!isset($node->args[1])) {
return null;
}
if (!$node->args[1] instanceof \PhpParser\Node\Arg) {
return null;
}
$secondArgValue = $node->args[1]->value;
if ($this->valueResolver->isTrue($secondArgValue)) {
$node->args[1]->value = $this->nodeFactory->createClassConstFetch('Carbon\\CarbonInterface', 'DIFF_ABSOLUTE');

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\CodeQuality;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\FuncCall;
@ -23,6 +24,10 @@ final class CompactConverter
public function hasAllArgumentsNamed(\PhpParser\Node\Expr\FuncCall $funcCall) : bool
{
foreach ($funcCall->args as $arg) {
// VariadicPlaceholder doesn't has name, so it return false directly
if (!$arg instanceof \PhpParser\Node\Arg) {
return \false;
}
/** @var string|null $variableName */
$variableName = $this->valueResolver->getValue($arg->value);
if (!\is_string($variableName)) {
@ -35,6 +40,9 @@ final class CompactConverter
{
$array = new \PhpParser\Node\Expr\Array_();
foreach ($funcCall->args as $arg) {
if (!$arg instanceof \PhpParser\Node\Arg) {
throw new \Rector\Core\Exception\ShouldNotHappenException();
}
/** @var string|null $variableName */
$variableName = $this->valueResolver->getValue($arg->value);
if (!\is_string($variableName)) {

View File

@ -119,6 +119,7 @@ CODE_SAMPLE
// get previous code
$new->args[1] = new \PhpParser\Node\Arg(new \PhpParser\Node\Expr\MethodCall($catchedThrowableVariable, 'getCode'));
}
/** @var Arg $arg1 */
$arg1 = $new->args[1];
if ($arg1->name instanceof \PhpParser\Node\Identifier && $arg1->name->toString() === 'previous') {
$new->args[1] = new \PhpParser\Node\Arg(new \PhpParser\Node\Expr\MethodCall($catchedThrowableVariable, 'getCode'));

View File

@ -5,6 +5,7 @@ namespace Rector\CodeQuality\Rector\For_;
use RectorPrefix20210927\Doctrine\Inflector\Inflector;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp;
@ -192,7 +193,7 @@ CODE_SAMPLE
continue;
}
$funcCall = $initExpr->expr;
if ($this->nodeNameResolver->isName($funcCall, self::COUNT)) {
if ($this->nodeNameResolver->isName($funcCall, self::COUNT) && $funcCall->args[0] instanceof \PhpParser\Node\Arg) {
$this->countValueVariableExpr = $initExpr->var;
$this->countValueName = $this->getName($initExpr->var);
$this->iteratedExpr = $funcCall->args[0]->value;
@ -219,7 +220,7 @@ CODE_SAMPLE
if (!$funcCall instanceof \PhpParser\Node\Expr\FuncCall) {
return \false;
}
if ($this->nodeNameResolver->isName($funcCall, self::COUNT)) {
if ($this->nodeNameResolver->isName($funcCall, self::COUNT) && $funcCall->args[0] instanceof \PhpParser\Node\Arg) {
$this->iteratedExpr = $funcCall->args[0]->value;
return \true;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\FunctionLike;
@ -54,6 +55,12 @@ CODE_SAMPLE
if (!$this->nodeNameResolver->isName($node, 'in_array')) {
return null;
}
if (!isset($node->args[1])) {
return null;
}
if (!$node->args[1] instanceof \PhpParser\Node\Arg) {
return null;
}
$arrayVariable = $node->args[1]->value;
/** @var Assign|Node|null $previousAssignArraysKeysFuncCall */
$previousAssignArraysKeysFuncCall = $this->betterNodeFinder->findFirstPreviousOfNode($node, function (\PhpParser\Node $node) use($arrayVariable) : bool {
@ -82,8 +89,20 @@ CODE_SAMPLE
$this->removeNode($previousAssignArraysKeysFuncCall);
return $this->createArrayKeyExists($node, $arrayKeysFuncCall);
}
private function createArrayKeyExists(\PhpParser\Node\Expr\FuncCall $inArrayFuncCall, \PhpParser\Node\Expr\FuncCall $arrayKeysFuncCall) : \PhpParser\Node\Expr\FuncCall
private function createArrayKeyExists(\PhpParser\Node\Expr\FuncCall $inArrayFuncCall, \PhpParser\Node\Expr\FuncCall $arrayKeysFuncCall) : ?\PhpParser\Node\Expr\FuncCall
{
if (!isset($inArrayFuncCall->args[0])) {
return null;
}
if (!$inArrayFuncCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
if (!isset($arrayKeysFuncCall->args[0])) {
return null;
}
if (!$arrayKeysFuncCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$arguments = [$inArrayFuncCall->args[0], $arrayKeysFuncCall->args[0]];
return new \PhpParser\Node\Expr\FuncCall(new \PhpParser\Node\Name('array_key_exists'), $arguments);
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\FuncCall;
@ -64,6 +65,10 @@ CODE_SAMPLE
}
$array = new \PhpParser\Node\Expr\Array_();
foreach ($node->args as $arg) {
// found non Arg? return early
if (!$arg instanceof \PhpParser\Node\Arg) {
return null;
}
$nestedArrayItem = $arg->value;
if (!$nestedArrayItem instanceof \PhpParser\Node\Expr\Array_) {
return null;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall;
@ -67,7 +68,14 @@ CODE_SAMPLE
return null;
}
// change the node
$firstArgValue = $node->args[0]->value;
if (!isset($node->args[0])) {
return null;
}
$firstArg = $node->args[0];
if (!$firstArg instanceof \PhpParser\Node\Arg) {
return null;
}
$firstArgValue = $firstArg->value;
if ($firstArgValue instanceof \PhpParser\Node\Expr\ArrowFunction) {
return $firstArgValue->expr;
}

View File

@ -66,9 +66,15 @@ CODE_SAMPLE
if (!$parent instanceof \PhpParser\Node\Stmt\Expression) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$arrayDimFetch = new \PhpParser\Node\Expr\ArrayDimFetch($node->args[0]->value);
$position = 1;
while (isset($node->args[$position])) {
while (isset($node->args[$position]) && $node->args[$position] instanceof \PhpParser\Node\Arg) {
$assign = new \PhpParser\Node\Expr\Assign($arrayDimFetch, $node->args[$position]->value);
$assignExpression = new \PhpParser\Node\Stmt\Expression($assign);
// keep comments of first line

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\Assign;
@ -89,7 +90,9 @@ CODE_SAMPLE
if ($this->compactConverter->hasAllArgumentsNamed($node)) {
return $this->compactConverter->convertToArray($node);
}
$firstValue = $node->args[0]->value;
/** @var Arg $firstArg */
$firstArg = $node->args[0];
$firstValue = $firstArg->value;
$firstValueStaticType = $this->getStaticType($firstValue);
if (!$firstValueStaticType instanceof \PHPStan\Type\Constant\ConstantArrayType) {
return null;
@ -123,7 +126,9 @@ CODE_SAMPLE
}
$this->removeNode($assign);
$this->arrayCompacter->compactStringToVariableArray($array);
$assignVariable = $funcCall->args[0]->value;
/** @var Arg $firstArg */
$firstArg = $funcCall->args[0];
$assignVariable = $firstArg->value;
$preAssign = new \PhpParser\Node\Expr\Assign($assignVariable, $array);
$currentStatement = $funcCall->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
$this->nodesToAddCollector->addNodeBeforeNode($preAssign, $currentStatement);

View File

@ -4,8 +4,10 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -14,6 +16,14 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class InArrayAndArrayKeysToArrayKeyExistsRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Simplify `in_array` and `array_keys` functions combination into `array_key_exists` when `array_keys` has one argument only', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample('in_array("key", array_keys($array), true);', 'array_key_exists("key", $array);')]);
@ -33,17 +43,23 @@ final class InArrayAndArrayKeysToArrayKeyExistsRector extends \Rector\Core\Recto
if (!$this->isName($node, 'in_array')) {
return null;
}
$secondArgument = $node->args[1]->value;
if (!$secondArgument instanceof \PhpParser\Node\Expr\FuncCall) {
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($node->args, [0, 1])) {
return null;
}
if (!$this->isName($secondArgument, 'array_keys')) {
/** @var Arg $secondArgument */
$secondArgument = $node->args[1];
if (!$secondArgument->value instanceof \PhpParser\Node\Expr\FuncCall) {
return null;
}
if (\count($secondArgument->args) > 1) {
if (!$this->isName($secondArgument->value, 'array_keys')) {
return null;
}
if (\count($secondArgument->value->args) > 1) {
return null;
}
/** @var Arg $keyArg */
$keyArg = $node->args[0];
/** @var Arg $arrayArg */
$arrayArg = $node->args[1];
/** @var FuncCall $innerFuncCallNode */
$innerFuncCallNode = $arrayArg->value;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Cast\Int_;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Rector\AbstractRector;
@ -53,13 +54,19 @@ CODE_SAMPLE
if (!$this->isName($node, 'intval')) {
return null;
}
if (isset($node->args[1])) {
if (isset($node->args[1]) && $node->args[1] instanceof \PhpParser\Node\Arg) {
$secondArgumentValue = $this->valueResolver->getValue($node->args[1]->value);
// default value
if ($secondArgumentValue !== 10) {
return null;
}
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
return new \PhpParser\Node\Expr\Cast\Int_($node->args[0]->value);
}
}

View File

@ -55,6 +55,9 @@ CODE_SAMPLE
if (isset($node->args[2])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$firstArgumentStaticType = $this->getStaticType($node->args[0]->value);
if (!$firstArgumentStaticType instanceof \PHPStan\Type\StringType) {
return null;

View File

@ -4,9 +4,11 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\StringType;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -15,6 +17,14 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class RemoveSoleValueSprintfRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Remove sprintf() wrapper if not needed', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
@ -61,14 +71,21 @@ CODE_SAMPLE
if (\count($node->args) !== 2) {
return null;
}
$maskArgument = $node->args[0]->value;
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($node->args, [0, 1])) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $node->args[0];
$maskArgument = $firstArg->value;
if (!$maskArgument instanceof \PhpParser\Node\Scalar\String_) {
return null;
}
if ($maskArgument->value !== '%s') {
return null;
}
$valueArgument = $node->args[1]->value;
/** @var Arg $secondArg */
$secondArg = $node->args[1];
$valueArgument = $secondArg->value;
if (!$this->nodeTypeResolver->isStaticType($valueArgument, \PHPStan\Type\StringType::class)) {
return null;
}

View File

@ -16,6 +16,7 @@ use PhpParser\Node\Expr\Cast\Object_;
use PhpParser\Node\Expr\Cast\String_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -31,6 +32,14 @@ final class SetTypeToCastRector extends \Rector\Core\Rector\AbstractRector
* @var array<string, class-string<Cast>>
*/
private const TYPE_TO_CAST = ['array' => \PhpParser\Node\Expr\Cast\Array_::class, 'bool' => \PhpParser\Node\Expr\Cast\Bool_::class, 'boolean' => \PhpParser\Node\Expr\Cast\Bool_::class, 'double' => \PhpParser\Node\Expr\Cast\Double::class, 'float' => \PhpParser\Node\Expr\Cast\Double::class, 'int' => \PhpParser\Node\Expr\Cast\Int_::class, 'integer' => \PhpParser\Node\Expr\Cast\Int_::class, 'object' => \PhpParser\Node\Expr\Cast\Object_::class, 'string' => \PhpParser\Node\Expr\Cast\String_::class];
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Changes settype() to (type) where possible', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
@ -72,12 +81,22 @@ CODE_SAMPLE
if (!$this->isName($node, 'settype')) {
return null;
}
$typeNode = $this->valueResolver->getValue($node->args[1]->value);
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->args, 1)) {
return null;
}
/** @var Arg $secondArg */
$secondArg = $node->args[1];
$typeNode = $this->valueResolver->getValue($secondArg->value);
if ($typeNode === null) {
return null;
}
$typeNode = \strtolower($typeNode);
$varNode = $node->args[0]->value;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->args, 0)) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $node->args[0];
$varNode = $firstArg->value;
$parentNode = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
// result of function or probably used
if ($parentNode instanceof \PhpParser\Node\Expr || $parentNode instanceof \PhpParser\Node\Arg) {

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -32,6 +33,9 @@ final class SimplifyFuncGetArgsCountRector extends \Rector\Core\Rector\AbstractR
if (!$this->isName($node, 'count')) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
if (!$node->args[0]->value instanceof \PhpParser\Node\Expr\FuncCall) {
return null;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -32,6 +33,12 @@ final class SimplifyInArrayValuesRector extends \Rector\Core\Rector\AbstractRect
if (!$this->isName($node, 'in_array')) {
return null;
}
if (!isset($node->args[1])) {
return null;
}
if (!$node->args[1] instanceof \PhpParser\Node\Arg) {
return null;
}
if (!$node->args[1]->value instanceof \PhpParser\Node\Expr\FuncCall) {
return null;
}
@ -40,6 +47,12 @@ final class SimplifyInArrayValuesRector extends \Rector\Core\Rector\AbstractRect
if (!$this->isName($innerFunCall, 'array_values')) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$node->args[1] = $innerFunCall->args[0];
return $node;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use Rector\Core\Rector\AbstractRector;
@ -36,6 +37,9 @@ final class SimplifyStrposLowerRector extends \Rector\Core\Rector\AbstractRector
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
if (!$node->args[0]->value instanceof \PhpParser\Node\Expr\FuncCall) {
return null;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\BinaryOp\Equal;
@ -58,6 +59,12 @@ CODE_SAMPLE
if (!$this->isName($node, 'in_array')) {
return null;
}
if (!isset($node->args[1])) {
return null;
}
if (!$node->args[1] instanceof \PhpParser\Node\Arg) {
return null;
}
if (!$node->args[1]->value instanceof \PhpParser\Node\Expr\Array_) {
return null;
}
@ -70,6 +77,12 @@ CODE_SAMPLE
if (!$firstArrayItem instanceof \PhpParser\Node\Expr\ArrayItem) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$firstArrayItemValue = $firstArrayItem->value;
// strict
if (isset($node->args[2])) {

View File

@ -4,7 +4,9 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -14,6 +16,14 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class UnwrapSprintfOneArgumentRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('unwrap sprintf() with one argument', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
@ -42,9 +52,14 @@ CODE_SAMPLE
if (\count($node->args) > 1) {
return null;
}
if ($node->args[0]->unpack) {
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->args, 0)) {
return null;
}
return $node->args[0]->value;
/** @var Arg $firstArg */
$firstArg = $node->args[0];
if ($firstArg->unpack) {
return null;
}
return $firstArg->value;
}
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\Identical;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
@ -63,6 +64,12 @@ final class GetClassToInstanceOfRector extends \Rector\Core\Rector\AbstractRecto
$firstExpr = $twoNodeMatch->getFirstExpr();
/** @var FuncCall $funcCall */
$funcCall = $twoNodeMatch->getSecondExpr();
if (!isset($funcCall->args[0])) {
return null;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$varNode = $funcCall->args[0]->value;
if ($firstExpr instanceof \PhpParser\Node\Scalar\String_) {
$className = $this->valueResolver->getValue($firstExpr);

View File

@ -4,10 +4,12 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\Identical;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -16,6 +18,14 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class StrlenZeroToIdenticalEmptyStringRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Changes strlen comparison to 0 to direct empty string compare', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
@ -50,27 +60,46 @@ CODE_SAMPLE
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
$variable = null;
if ($node->left instanceof \PhpParser\Node\Expr\FuncCall) {
if (!$this->isName($node->left, 'strlen')) {
return null;
}
if (!$this->valueResolver->isValue($node->right, 0)) {
return null;
}
$variable = $node->left->args[0]->value;
} elseif ($node->right instanceof \PhpParser\Node\Expr\FuncCall) {
if (!$this->isName($node->right, 'strlen')) {
return null;
}
if (!$this->valueResolver->isValue($node->left, 0)) {
return null;
}
$variable = $node->right->args[0]->value;
} else {
return $this->processLeftIdentical($node, $node->left);
}
if ($node->right instanceof \PhpParser\Node\Expr\FuncCall) {
return $this->processRightIdentical($node, $node->right);
}
return null;
}
private function processLeftIdentical(\PhpParser\Node\Expr\BinaryOp\Identical $identical, \PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr\BinaryOp\Identical
{
if (!$this->isName($funcCall, 'strlen')) {
return null;
}
if (!$this->valueResolver->isValue($identical->right, 0)) {
return null;
}
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($funcCall->args, 0)) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $funcCall->args[0];
/** @var Expr $variable */
$variable = $firstArg->value;
return new \PhpParser\Node\Expr\BinaryOp\Identical($variable, new \PhpParser\Node\Scalar\String_(''));
}
private function processRightIdentical(\PhpParser\Node\Expr\BinaryOp\Identical $identical, \PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr\BinaryOp\Identical
{
if (!$this->isName($funcCall, 'strlen')) {
return null;
}
if (!$this->valueResolver->isValue($identical->left, 0)) {
return null;
}
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($funcCall->args, 0)) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $funcCall->args[0];
/** @var Expr $variable */
$variable = $firstArg->value;
return new \PhpParser\Node\Expr\BinaryOp\Identical($variable, new \PhpParser\Node\Scalar\String_(''));
}
}

View File

@ -14,6 +14,7 @@ use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -22,6 +23,14 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class SimplifyIfIssetToNullCoalescingRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Simplify binary if to null coalesce', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
@ -90,10 +99,17 @@ CODE_SAMPLE
if (!$this->isName($firstAssign->expr, 'array_merge')) {
return null;
}
if (!$this->nodeComparator->areNodesEqual($firstAssign->expr->args[0]->value, $valueNode)) {
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($firstAssign->expr->args, [0, 1])) {
return null;
}
if (!$this->nodeComparator->areNodesEqual($secondAssign->expr, $firstAssign->expr->args[1]->value)) {
/** @var Arg $firstArg */
$firstArg = $firstAssign->expr->args[0];
if (!$this->nodeComparator->areNodesEqual($firstArg->value, $valueNode)) {
return null;
}
/** @var Arg $secondArg */
$secondArg = $firstAssign->expr->args[1];
if (!$this->nodeComparator->areNodesEqual($secondAssign->expr, $secondArg->value)) {
return null;
}
$args = [new \PhpParser\Node\Arg(new \PhpParser\Node\Expr\BinaryOp\Coalesce($valueNode, new \PhpParser\Node\Expr\Array_([]))), new \PhpParser\Node\Arg($secondAssign->expr)];

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\Ternary;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\BinaryOp\Coalesce;
use PhpParser\Node\Expr\FuncCall;
@ -78,8 +79,16 @@ CODE_SAMPLE
*/
private function areArrayKeysExistsArgsMatchingDimFetch(\PhpParser\Node\Expr\FuncCall $funcCall, \PhpParser\Node\Expr\ArrayDimFetch $arrayDimFetch) : bool
{
$keyExpr = $funcCall->args[0]->value;
$valuesExpr = $funcCall->args[1]->value;
$firstArg = $funcCall->args[0];
if (!$firstArg instanceof \PhpParser\Node\Arg) {
return \false;
}
$keyExpr = $firstArg->value;
$secondArg = $funcCall->args[1];
if (!$secondArg instanceof \PhpParser\Node\Arg) {
return \false;
}
$valuesExpr = $secondArg->value;
if (!$this->nodeComparator->areNodesEqual($arrayDimFetch->var, $valuesExpr)) {
return \false;
}

View File

@ -3,9 +3,11 @@
declare (strict_types=1);
namespace Rector\CodingStyle\NodeAnalyzer;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\NodeNameResolver\NodeNameResolver;
final class ImplodeAnalyzer
{
@ -13,9 +15,14 @@ final class ImplodeAnalyzer
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->argsAnalyzer = $argsAnalyzer;
}
/**
* Matches: "implode('","', $items)"
@ -28,10 +35,15 @@ final class ImplodeAnalyzer
if (!$this->nodeNameResolver->isName($expr, 'implode')) {
return \false;
}
if (!isset($expr->args[1])) {
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($expr->args, 1)) {
return \false;
}
$firstArgumentValue = $expr->args[0]->value;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($expr->args, 0)) {
return \false;
}
/** @var Arg $firstArg */
$firstArg = $expr->args[0];
$firstArgumentValue = $firstArg->value;
if (!$firstArgumentValue instanceof \PhpParser\Node\Scalar\String_) {
return \true;
}

View File

@ -5,6 +5,7 @@ namespace Rector\CodingStyle\NodeFactory;
use RectorPrefix20210927\Nette\Utils\Json;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
@ -62,8 +63,14 @@ final class JsonArrayFactory
}
$placeholderNode = $this->matchPlaceholderNode($onlyItem->value, $placeholderNodes);
if ($placeholderNode && $this->implodeAnalyzer->isImplodeToJson($placeholderNode)) {
/** @var FuncCall $placeholderNode */
return $placeholderNode->args[1]->value;
/**
* @var FuncCall $placeholderNode
* @var Arg $firstArg
*
* Arg check already on $this->implodeAnalyzer->isImplodeToJson() above
*/
$firstArg = $placeholderNode->args[1];
return $firstArg->value;
}
}
return $this->matchPlaceholderNode($node, $placeholderNodes);

View File

@ -146,6 +146,9 @@ CODE_SAMPLE
if ($position < $firstSpreadParamPosition) {
continue;
}
if (!$arg instanceof \PhpParser\Node\Arg) {
continue;
}
$variadicArgs[] = $arg;
}
return $variadicArgs;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodingStyle\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\BinaryOp;
@ -16,6 +17,7 @@ use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty;
use PHPStan\Type\Type;
use Rector\CodingStyle\TypeAnalyzer\IterableTypeAnalyzer;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
@ -35,10 +37,15 @@ final class AddArrayDefaultToArrayPropertyRector extends \Rector\Core\Rector\Abs
* @var \Rector\CodingStyle\TypeAnalyzer\IterableTypeAnalyzer
*/
private $iterableTypeAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer $propertyFetchAnalyzer, \Rector\CodingStyle\TypeAnalyzer\IterableTypeAnalyzer $iterableTypeAnalyzer)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer $propertyFetchAnalyzer, \Rector\CodingStyle\TypeAnalyzer\IterableTypeAnalyzer $iterableTypeAnalyzer, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->propertyFetchAnalyzer = $propertyFetchAnalyzer;
$this->iterableTypeAnalyzer = $iterableTypeAnalyzer;
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -152,10 +159,12 @@ CODE_SAMPLE
if (!$this->isName($node, 'count')) {
return null;
}
if (!isset($node->args[0])) {
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->args, 0)) {
return null;
}
$countedArgument = $node->args[0]->value;
/** @var Arg $firstArg */
$firstArg = $node->args[0];
$countedArgument = $firstArg->value;
if (!$countedArgument instanceof \PhpParser\Node\Expr\PropertyFetch) {
return null;
}

View File

@ -11,6 +11,7 @@ use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Scalar\String_;
use Rector\CodingStyle\NodeFactory\ArrayCallableToMethodCallFactory;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
@ -28,9 +29,14 @@ final class CallUserFuncArrayToVariadicRector extends \Rector\Core\Rector\Abstra
* @var \Rector\CodingStyle\NodeFactory\ArrayCallableToMethodCallFactory
*/
private $arrayCallableToMethodCallFactory;
public function __construct(\Rector\CodingStyle\NodeFactory\ArrayCallableToMethodCallFactory $arrayCallableToMethodCallFactory)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\CodingStyle\NodeFactory\ArrayCallableToMethodCallFactory $arrayCallableToMethodCallFactory, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->arrayCallableToMethodCallFactory = $arrayCallableToMethodCallFactory;
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -69,8 +75,15 @@ CODE_SAMPLE
if (!$this->isName($node, 'call_user_func_array')) {
return null;
}
$firstArgValue = $node->args[0]->value;
$secondArgValue = $node->args[1]->value;
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($node->args, [0, 1])) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $node->args[0];
$firstArgValue = $firstArg->value;
/** @var Arg $secondArg */
$secondArg = $node->args[1];
$secondArgValue = $secondArg->value;
if ($firstArgValue instanceof \PhpParser\Node\Scalar\String_) {
$functionName = $this->valueResolver->getValue($firstArgValue);
return $this->createFuncCall($secondArgValue, $functionName);

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodingStyle\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
@ -63,6 +64,12 @@ CODE_SAMPLE
if (!$this->isName($node, 'call_user_func')) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$firstArgValue = $node->args[0]->value;
if (!$firstArgValue instanceof \PhpParser\Node\Expr\Array_) {
return null;

View File

@ -7,6 +7,7 @@ use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\TypeAnalyzer\StringTypeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -22,9 +23,14 @@ final class ConsistentImplodeRector extends \Rector\Core\Rector\AbstractRector
* @var \Rector\NodeTypeResolver\TypeAnalyzer\StringTypeAnalyzer
*/
private $stringTypeAnalyzer;
public function __construct(\Rector\NodeTypeResolver\TypeAnalyzer\StringTypeAnalyzer $stringTypeAnalyzer)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\NodeTypeResolver\TypeAnalyzer\StringTypeAnalyzer $stringTypeAnalyzer, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->stringTypeAnalyzer = $stringTypeAnalyzer;
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -75,13 +81,27 @@ CODE_SAMPLE
$node->args[0] = new \PhpParser\Node\Arg(new \PhpParser\Node\Scalar\String_(''));
return $node;
}
$firstArgumentValue = $node->args[0]->value;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->args, 0)) {
return null;
}
/** @var Arg $arg0 */
$arg0 = $node->args[0];
$firstArgumentValue = $arg0->value;
if ($firstArgumentValue instanceof \PhpParser\Node\Scalar\String_) {
return null;
}
if (\count($node->args) === 2 && $this->stringTypeAnalyzer->isStringOrUnionStringOnlyType($node->args[1]->value)) {
$node->args = \array_reverse($node->args);
if (\count($node->args) !== 2) {
return null;
}
return $node;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->args, 1)) {
return null;
}
/** @var Arg $arg1 */
$arg1 = $node->args[1];
if ($this->stringTypeAnalyzer->isStringOrUnionStringOnlyType($arg1->value)) {
$node->args = \array_reverse($node->args);
return $node;
}
return null;
}
}

View File

@ -92,6 +92,9 @@ CODE_SAMPLE
if (!$this->isName($node->name, $method)) {
continue;
}
if (!$node->args[$position] instanceof \PhpParser\Node\Arg) {
continue;
}
$this->refactorArgument($node->args[$position]);
return $node;
}
@ -108,6 +111,9 @@ CODE_SAMPLE
if (!$this->isName($funcCall, $function)) {
continue;
}
if (!$funcCall->args[$position] instanceof \PhpParser\Node\Arg) {
continue;
}
$this->refactorArgument($funcCall->args[$position]);
return $funcCall;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodingStyle\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\BinaryOp\Greater;
@ -58,6 +59,12 @@ CODE_SAMPLE
if (!$this->isName($node, 'count')) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
/** @var Expr $expr */
$expr = $node->args[0]->value;
// not pass array type, skip
@ -90,6 +97,12 @@ CODE_SAMPLE
if (!$this->isName($booleanNot->expr, 'count')) {
return null;
}
if (!isset($booleanNot->expr->args[0])) {
return null;
}
if (!$booleanNot->expr->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
/** @var Expr $expr */
$expr = $booleanNot->expr->args[0]->value;
// not pass array type, skip

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodingStyle\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\Greater;
@ -17,6 +18,7 @@ use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Util\PhpVersionFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -34,9 +36,14 @@ final class VersionCompareFuncCallToConstantRector extends \Rector\Core\Rector\A
* @var \Rector\Core\Util\PhpVersionFactory
*/
private $phpVersionFactory;
public function __construct(\Rector\Core\Util\PhpVersionFactory $phpVersionFactory)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\Util\PhpVersionFactory $phpVersionFactory, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->phpVersionFactory = $phpVersionFactory;
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -78,11 +85,16 @@ CODE_SAMPLE
if (\count($node->args) !== 3) {
return null;
}
if (!$this->isPhpVersionConstant($node->args[0]->value) && !$this->isPhpVersionConstant($node->args[1]->value)) {
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($node->args, [0, 1, 2])) {
return null;
}
$left = $this->getNewNodeForArg($node->args[0]->value);
$right = $this->getNewNodeForArg($node->args[1]->value);
/** @var Arg[] $args */
$args = $node->args;
if (!$this->isPhpVersionConstant($args[0]->value) && !$this->isPhpVersionConstant($args[1]->value)) {
return null;
}
$left = $this->getNewNodeForArg($args[0]->value);
$right = $this->getNewNodeForArg($args[1]->value);
if ($left === null) {
return null;
}
@ -90,7 +102,7 @@ CODE_SAMPLE
return null;
}
/** @var String_ $operator */
$operator = $node->args[2]->value;
$operator = $args[2]->value;
$comparisonClass = self::OPERATOR_TO_COMPARISON[$operator->value];
return new $comparisonClass($left, $right);
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodingStyle\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
@ -62,6 +63,9 @@ CODE_SAMPLE
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$argValue = $node->args[0]->value;
if (!$argValue instanceof \PhpParser\Node\Expr\FuncCall) {
return null;
@ -72,6 +76,9 @@ CODE_SAMPLE
$messageVariable = new \PhpParser\Node\Expr\Variable('message');
$assign = new \PhpParser\Node\Expr\Assign($messageVariable, $argValue);
$this->nodesToAddCollector->addNodeBeforeNode($assign, $node);
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$node->args[0]->value = $messageVariable;
return $node;
}

View File

@ -7,6 +7,7 @@ use PhpParser\Node\Arg;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\VariadicPlaceholder;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
@ -63,7 +64,7 @@ final class CurrentAndParentClassMethodComparator
return $this->nodeNameResolver->isName($staticCall->class, 'parent');
}
/**
* @param Arg[] $parentStaticCallArgs
* @param Arg[]|VariadicPlaceholder[] $parentStaticCallArgs
* @param Param[] $currentClassMethodParams
*/
private function areArgsAndParamsEqual(array $parentStaticCallArgs, array $currentClassMethodParams) : bool
@ -78,6 +79,9 @@ final class CurrentAndParentClassMethodComparator
if (!isset($currentClassMethodParams[$key])) {
return \false;
}
if (!$arg instanceof \PhpParser\Node\Arg) {
continue;
}
// this only compares variable name, but those can be differnt, so its kinda useless
$param = $currentClassMethodParams[$key];
if (!$this->nodeComparator->areNodesEqual($param->var, $arg->value)) {

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DeadCode;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Equal;
use PhpParser\Node\Expr\BinaryOp\Identical;
@ -88,7 +89,7 @@ final class ConditionResolver
}
// includes compare sign as 3rd argument
$versionCompareSign = null;
if (isset($funcCall->args[2])) {
if (isset($funcCall->args[2]) && $funcCall->args[2] instanceof \PhpParser\Node\Arg) {
$versionCompareSign = $this->valueResolver->getValue($funcCall->args[2]->value);
}
return new \Rector\DeadCode\ValueObject\VersionCompareCondition($firstVersion, $secondVersion, $versionCompareSign);
@ -104,6 +105,12 @@ final class ConditionResolver
}
private function resolveArgumentValue(\PhpParser\Node\Expr\FuncCall $funcCall, int $argumentPosition) : ?int
{
if (!isset($funcCall->args[$argumentPosition])) {
return null;
}
if (!$funcCall->args[$argumentPosition] instanceof \PhpParser\Node\Arg) {
return null;
}
$firstArgValue = $funcCall->args[$argumentPosition]->value;
/** @var mixed|null $version */
$version = $this->valueResolver->getValue($firstArgValue);

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DeadCode\NodeManipulator;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Greater;
use PhpParser\Node\Expr\BinaryOp\GreaterOrEqual;
@ -91,6 +92,12 @@ final class CountManipulator
if (!$this->nodeNameResolver->isName($node, 'count')) {
return \false;
}
if (!isset($node->args[0])) {
return \false;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return \false;
}
$countedExpr = $node->args[0]->value;
return $this->nodeComparator->areNodesEqual($countedExpr, $expr);
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DeadCode\Rector\Assign;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
@ -153,6 +154,9 @@ CODE_SAMPLE
private function isUsedInAssignExpr($expr, \PhpParser\Node\Expr\Assign $assign) : bool
{
foreach ($expr->args as $arg) {
if (!$arg instanceof \PhpParser\Node\Arg) {
continue;
}
$variable = $arg->value;
if (!$variable instanceof \PhpParser\Node\Expr\Variable) {
continue;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DeadCode\Rector\If_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassLike;
@ -83,6 +84,12 @@ CODE_SAMPLE
}
/** @var FuncCall $funcCall */
$funcCall = $node->cond;
if (!isset($funcCall->args[0])) {
return null;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$functionToExistName = $this->valueResolver->getValue($funcCall->args[0]->value);
if (!\is_string($functionToExistName)) {
return null;

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\Defluent\NodeAnalyzer;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PHPStan\Type\MixedType;
@ -34,6 +35,12 @@ final class NewFluentChainMethodCallNodeAnalyzer
if (\count($methodCall->args) !== 1) {
return null;
}
if (!isset($methodCall->args[0])) {
return null;
}
if (!$methodCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$onlyArgValue = $methodCall->args[0]->value;
if (!$onlyArgValue instanceof \PhpParser\Node\Expr\New_) {
return null;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DependencyInjection\NodeRemover;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
@ -81,6 +82,9 @@ final class ClassMethodNodeRemover
private function removeParamFromArgs(\PhpParser\Node\Expr\StaticCall $staticCall, string $paramName) : void
{
foreach ($staticCall->args as $key => $arg) {
if (!$arg instanceof \PhpParser\Node\Arg) {
continue;
}
if (!$this->nodeNameResolver->isName($arg->value, $paramName)) {
continue;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DowngradePhp70\Rector\Expression;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Const_;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\FuncCall;
@ -11,6 +12,7 @@ use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Function_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeNestingScope\ParentFinder;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -24,9 +26,14 @@ final class DowngradeDefineArrayConstantRector extends \Rector\Core\Rector\Abstr
* @var \Rector\NodeNestingScope\ParentFinder
*/
private $parentFinder;
public function __construct(\Rector\NodeNestingScope\ParentFinder $parentFinder)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\NodeNestingScope\ParentFinder $parentFinder, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->parentFinder = $parentFinder;
$this->argsAnalyzer = $argsAnalyzer;
}
/**
* @return array<class-string<Node>>
@ -65,11 +72,13 @@ CODE_SAMPLE
if ($this->shouldSkip($funcCall)) {
return null;
}
/** @var Arg[] $args */
$args = $funcCall->args;
/** @var String_ $arg0 */
$arg0 = $funcCall->args[0]->value;
$arg0 = $args[0]->value;
$arg0Value = $arg0->value;
/** @var Array_ $arg1Value */
$arg1Value = $funcCall->args[1]->value;
$arg1Value = $args[1]->value;
return new \PhpParser\Node\Stmt\Const_([new \PhpParser\Node\Const_($arg0Value, $arg1Value)]);
}
private function shouldSkip(\PhpParser\Node\Expr\FuncCall $funcCall) : bool
@ -78,6 +87,10 @@ CODE_SAMPLE
return \true;
}
$args = $funcCall->args;
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($args, [0, 1])) {
return \true;
}
/** @var Arg[] $args */
if (!$args[0]->value instanceof \PhpParser\Node\Scalar\String_) {
return \true;
}

View File

@ -49,6 +49,12 @@ CODE_SAMPLE
return null;
}
$currentStatement = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
/** @var Array_ $options */
$options = $node->args[0]->value;
foreach ($options->items as $option) {
@ -77,6 +83,9 @@ CODE_SAMPLE
if (!isset($funcCall->args[0])) {
return \true;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return \true;
}
return !$funcCall->args[0]->value instanceof \PhpParser\Node\Expr\Array_;
}
}

View File

@ -11,6 +11,7 @@ use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\VariadicPlaceholder;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -60,6 +61,7 @@ CODE_SAMPLE
foreach ($array->items as $arrayItem) {
$args[] = $arrayItem instanceof \PhpParser\Node\Expr\ArrayItem ? new \PhpParser\Node\Arg($arrayItem->value) : null;
}
/** @var Arg[]|VariadicPlaceholder[] $args */
return new \PhpParser\Node\Expr\FuncCall(new \PhpParser\Node\Name('list'), $args);
}
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DowngradePhp71\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Instanceof_;
@ -55,6 +56,12 @@ CODE_SAMPLE
if (!$this->isName($node, 'is_iterable')) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
/** @var mixed $arg */
$arg = $node->args[0]->value;
$funcCall = $this->nodeFactory->createFuncCall('is_array', [$arg]);

View File

@ -61,6 +61,12 @@ CODE_SAMPLE
if ($this->shouldSkip($node)) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$tempVariableName = $this->variableNaming->createCountedValueName('callable', $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE));
$tempVariable = new \PhpParser\Node\Expr\Variable($tempVariableName);
$expression = new \PhpParser\Node\Stmt\Expression(new \PhpParser\Node\Expr\Assign($tempVariable, $node->args[0]->value));

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DowngradePhp71\Rector\String_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\BinaryOp\Minus;
@ -85,11 +86,17 @@ CODE_SAMPLE
if (!isset($args[2])) {
return null;
}
if (!$args[2]->value instanceof \PhpParser\Node\Expr\UnaryMinus) {
if ($args[2] instanceof \PhpParser\Node\Arg && !$args[2]->value instanceof \PhpParser\Node\Expr\UnaryMinus) {
return null;
}
if (!$args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
if (!$funcCall->args[2] instanceof \PhpParser\Node\Arg) {
return null;
}
$strlenFuncCall = $this->nodeFactory->createFuncCall('strlen', [$args[0]]);
$funcCall->args[2]->value = new \PhpParser\Node\Expr\BinaryOp\Minus($strlenFuncCall, $args[2]->value->expr);
$funcCall->args[2]->value = new \PhpParser\Node\Expr\BinaryOp\Minus($strlenFuncCall, $funcCall->args[2]->value->expr);
return $funcCall;
}
}

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\DowngradePhp72\NodeAnalyzer;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Stmt\If_;
@ -44,6 +45,12 @@ final class FunctionExistsFunCallAnalyzer
}
/** @var FuncCall $functionExists */
$functionExists = $firstParentIf->cond;
if (!isset($functionExists->args[0])) {
return \false;
}
if (!$functionExists->args[0] instanceof \PhpParser\Node\Arg) {
return \false;
}
return $this->valueResolver->isValue($functionExists->args[0]->value, $functionName);
}
}

View File

@ -5,6 +5,7 @@ namespace Rector\DowngradePhp72\Rector\FuncCall;
use RectorPrefix20210927\Nette\NotImplementedException;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp\BitwiseOr;
@ -66,7 +67,7 @@ final class DowngradePregUnmatchedAsNullConstantRector extends \Rector\Core\Rect
if (!$this->isRegexFunctionNames($node)) {
return null;
}
$args = $node->args;
$args = $node->getArgs();
if (!isset($args[3])) {
return null;
}
@ -75,7 +76,7 @@ final class DowngradePregUnmatchedAsNullConstantRector extends \Rector\Core\Rect
$variable = $args[2]->value;
if ($flags instanceof \PhpParser\Node\Expr\BinaryOp\BitwiseOr) {
$this->cleanBitWiseOrFlags($node, $flags);
if (!$this->nodeComparator->areNodesEqual($flags, $node->args[3]->value)) {
if (!$this->nodeComparator->areNodesEqual($flags, $args[3]->value)) {
return $this->handleEmptyStringToNullMatch($node, $variable);
}
return null;
@ -193,6 +194,9 @@ CODE_SAMPLE
if ($bitwiseOr instanceof \PhpParser\Node\Expr\BinaryOp\BitwiseOr && $bitwiseOr->left instanceof \PhpParser\Node\Expr\ConstFetch && $this->isName($bitwiseOr->left, self::FLAG)) {
$bitwiseOr = $bitwiseOr->right;
}
if (!$funcCall->args[3] instanceof \PhpParser\Node\Arg) {
return;
}
$funcCall->args[3]->value = $bitwiseOr;
}
private function handleEmptyStringToNullMatch(\PhpParser\Node\Expr\FuncCall $funcCall, \PhpParser\Node\Expr\Variable $variable) : \PhpParser\Node\Expr\FuncCall

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DowngradePhp73\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use Rector\Core\Rector\AbstractRector;
@ -59,16 +60,28 @@ CODE_SAMPLE
}
return null;
}
private function refactorArrayKeyFirst(\PhpParser\Node\Expr\FuncCall $funcCall) : \PhpParser\Node\Expr\FuncCall
private function refactorArrayKeyFirst(\PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr\FuncCall
{
if (!isset($funcCall->args[0])) {
return null;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$array = $funcCall->args[0]->value;
$resetFuncCall = $this->nodeFactory->createFuncCall('reset', [$array]);
$this->nodesToAddCollector->addNodeBeforeNode($resetFuncCall, $funcCall);
$funcCall->name = new \PhpParser\Node\Name('key');
return $funcCall;
}
private function refactorArrayKeyLast(\PhpParser\Node\Expr\FuncCall $funcCall) : \PhpParser\Node\Expr\FuncCall
private function refactorArrayKeyLast(\PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr\FuncCall
{
if (!isset($funcCall->args[0])) {
return null;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$array = $funcCall->args[0]->value;
$resetFuncCall = $this->nodeFactory->createFuncCall('end', [$array]);
$this->nodesToAddCollector->addNodeBeforeNode($resetFuncCall, $funcCall);

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DowngradePhp73\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Instanceof_;
@ -45,6 +46,12 @@ CODE_SAMPLE
if (!$this->isName($node, 'is_countable')) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$isArrayFuncCall = $this->nodeFactory->createFuncCall('is_array', $node->args);
$instanceof = new \PhpParser\Node\Expr\Instanceof_($node->args[0]->value, new \PhpParser\Node\Name\FullyQualified('Countable'));
return new \PhpParser\Node\Expr\BinaryOp\BooleanOr($isArrayFuncCall, $instanceof);

View File

@ -11,6 +11,7 @@ use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -33,6 +34,10 @@ final class SetCookieOptionsArrayToArgumentsRector extends \Rector\Core\Rector\A
* @var int
*/
private $highestIndex = 1;
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Convert setcookie option array to arguments', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
@ -43,6 +48,10 @@ setcookie('name', $value, 360);
CODE_SAMPLE
)]);
}
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
/**
* @return array<class-string<Node>>
*/
@ -73,7 +82,7 @@ CODE_SAMPLE
if (!isset($funcCall->args[2])) {
return \true;
}
return !$funcCall->args[2]->value instanceof \PhpParser\Node\Expr\Array_;
return !($funcCall->args[2] instanceof \PhpParser\Node\Arg && $funcCall->args[2]->value instanceof \PhpParser\Node\Expr\Array_);
}
/**
* @return Arg[]
@ -81,9 +90,18 @@ CODE_SAMPLE
private function composeNewArgs(\PhpParser\Node\Expr\FuncCall $funcCall) : array
{
$this->highestIndex = 1;
$newArgs = [$funcCall->args[0], $funcCall->args[1]];
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($funcCall->args, [0, 1, 2])) {
return [];
}
/** @var Arg $firstArg */
$firstArg = $funcCall->args[0];
/** @var Arg $secondArg */
$secondArg = $funcCall->args[1];
$newArgs = [$firstArg, $secondArg];
/** @var Arg $thirdArg */
$thirdArg = $funcCall->args[2];
/** @var Array_ $optionsArray */
$optionsArray = $funcCall->args[2]->value;
$optionsArray = $thirdArg->value;
/** @var ArrayItem|null $arrayItem */
foreach ($optionsArray->items as $arrayItem) {
if ($arrayItem === null) {

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\DowngradePhp74\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\ComplexType;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
@ -143,7 +144,7 @@ CODE_SAMPLE
return $node;
}
/**
* @param \PhpParser\Node\UnionType|\PhpParser\Node\NullableType|\PhpParser\Node\Name|\PhpParser\Node\Identifier $returnTypeNode
* @param \PhpParser\Node\UnionType|\PhpParser\Node\NullableType|\PhpParser\Node\Name|\PhpParser\Node\Identifier|\PhpParser\Node\ComplexType $returnTypeNode
*/
private function resolveDifferentAncestorReturnType(\PhpParser\Node\Stmt\ClassMethod $classMethod, $returnTypeNode) : \PHPStan\Type\Type
{

View File

@ -90,7 +90,9 @@ CODE_SAMPLE
if ($this->shouldSkipFuncCall($node)) {
return null;
}
$allowableTagsParam = $node->args[1]->value;
/** @var Arg $secondArg */
$secondArg = $node->args[1];
$allowableTagsParam = $secondArg->value;
if ($allowableTagsParam instanceof \PhpParser\Node\Expr\Array_) {
// If it is an array, convert it to string
$newExpr = $this->createArrayFromString($allowableTagsParam);
@ -121,6 +123,12 @@ CODE_SAMPLE
if (\count($funcCall->args) < 2) {
return \true;
}
if (!isset($funcCall->args[1])) {
return \true;
}
if (!$funcCall->args[1] instanceof \PhpParser\Node\Arg) {
return \true;
}
// Process anything other than String and null (eg: variables, function calls)
$allowableTagsParam = $funcCall->args[1]->value;
// Skip for string

View File

@ -97,10 +97,11 @@ CODE_SAMPLE
*/
private function processArgs($node) : ?\PhpParser\Node
{
if ($node->args === []) {
$args = $node->getArgs();
if ($args === []) {
return null;
}
return $this->cleanTrailingComma($node, $node->args);
return $this->cleanTrailingComma($node, $args);
}
private function processUses(\PhpParser\Node\Expr\Closure $node) : void
{

View File

@ -4,10 +4,12 @@ declare (strict_types=1);
namespace Rector\DowngradePhp80\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -18,6 +20,14 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class DowngradeStrContainsRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Replace str_contains() with strpos() !== false', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
@ -57,8 +67,15 @@ CODE_SAMPLE
if (!$funcCall instanceof \PhpParser\Node\Expr\FuncCall) {
return null;
}
$haystack = $funcCall->args[0]->value;
$needle = $funcCall->args[1]->value;
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($funcCall->args, [0, 1])) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $funcCall->args[0];
$haystack = $firstArg->value;
/** @var Arg $secondArg */
$secondArg = $funcCall->args[1];
$needle = $secondArg->value;
$funcCall = $this->nodeFactory->createFuncCall('strpos', [$haystack, $needle]);
if ($node instanceof \PhpParser\Node\Expr\BooleanNot) {
return new \PhpParser\Node\Expr\BinaryOp\Identical($funcCall, $this->nodeFactory->createFalse());

View File

@ -52,8 +52,8 @@ final class DowngradeStrEndsWithRector extends \Rector\Core\Rector\AbstractRecto
}
private function createSubstrCompareFuncCall(\PhpParser\Node\Expr\FuncCall $funcCall) : \PhpParser\Node\Expr\FuncCall
{
$args = $funcCall->args;
$strlenFuncCall = $this->createStrlenFuncCall($funcCall->args[1]->value);
$args = $funcCall->getArgs();
$strlenFuncCall = $this->createStrlenFuncCall($args[1]->value);
$args[] = new \PhpParser\Node\Arg(new \PhpParser\Node\Expr\UnaryMinus($strlenFuncCall));
return new \PhpParser\Node\Expr\FuncCall(new \PhpParser\Node\Name('substr_compare'), $args);
}

View File

@ -77,7 +77,7 @@ CODE_SAMPLE
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
$args = $node->args;
$args = $node->getArgs();
if ($this->shouldSkip($args)) {
return null;
}

View File

@ -98,11 +98,19 @@ CODE_SAMPLE
if (!$this->nodeTypeResolver->isObjectTypes($methodCall->var, [new \PHPStan\Type\ObjectType('League\\Event\\EventDispatcher'), new \PHPStan\Type\ObjectType('League\\Event\\Emitter')])) {
return \true;
}
if (!isset($methodCall->args[0])) {
return \true;
}
if (!$methodCall->args[0] instanceof \PhpParser\Node\Arg) {
return \true;
}
return !$this->getStaticType($methodCall->args[0]->value) instanceof \PHPStan\Type\StringType;
}
private function updateNode(\PhpParser\Node\Expr\MethodCall $methodCall) : \PhpParser\Node\Expr\MethodCall
{
$methodCall->args[0] = new \PhpParser\Node\Arg($this->createNewAnonymousEventClass($methodCall->args[0]->value));
/** @var Arg $firstArg */
$firstArg = $methodCall->args[0];
$methodCall->args[0] = new \PhpParser\Node\Arg($this->createNewAnonymousEventClass($firstArg->value));
return $methodCall;
}
private function createNewAnonymousEventClass(\PhpParser\Node\Expr $expr) : \PhpParser\Node\Expr\New_

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\MockeryToProphecy\Collector;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\StaticCall;
@ -43,6 +44,12 @@ final class MockVariableCollector
$variable = $parentNode->var;
/** @var string $variableName */
$variableName = $this->nodeNameResolver->getName($variable);
if (!isset($node->args[0])) {
return [];
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return [];
}
$type = $node->args[0]->value;
$mockedType = $this->valueResolver->getValue($type);
$mockVariableTypesByNames[$variableName] = $mockedType;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\MysqlToMysqli\Rector\Assign;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
@ -111,7 +112,7 @@ CODE_SAMPLE
private function processMysqlResult(\PhpParser\Node\Expr\Assign $assign, \PhpParser\Node\Expr\FuncCall $funcCall) : \PhpParser\Node\Expr\FuncCall
{
$fetchField = null;
if (isset($funcCall->args[2])) {
if (isset($funcCall->args[2]) && $funcCall->args[2] instanceof \PhpParser\Node\Arg) {
$fetchField = $funcCall->args[2]->value;
unset($funcCall->args[2]);
}

View File

@ -44,7 +44,7 @@ CODE_SAMPLE
/**
* @param FuncCall $node
*/
public function refactor(\PhpParser\Node $node) : \PhpParser\Node\Expr\FuncCall
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node\Expr\FuncCall
{
if ($this->isName($node, 'mysql_create_db')) {
return $this->processMysqlCreateDb($node);
@ -56,25 +56,37 @@ CODE_SAMPLE
$node->name = new \PhpParser\Node\Name(self::MYSQLI_QUERY);
$node->args[0] = new \PhpParser\Node\Arg(new \PhpParser\Node\Scalar\String_('SHOW DATABASES'));
}
if ($this->isName($node, 'mysql_list_fields')) {
if ($this->isName($node, 'mysql_list_fields') && $node->args[0] instanceof \PhpParser\Node\Arg && $node->args[1] instanceof \PhpParser\Node\Arg) {
$node->name = new \PhpParser\Node\Name(self::MYSQLI_QUERY);
$node->args[0]->value = $this->joinStringWithNode('SHOW COLUMNS FROM', $node->args[1]->value);
unset($node->args[1]);
}
if ($this->isName($node, 'mysql_list_tables')) {
if ($this->isName($node, 'mysql_list_tables') && $node->args[0] instanceof \PhpParser\Node\Arg) {
$node->name = new \PhpParser\Node\Name(self::MYSQLI_QUERY);
$node->args[0]->value = $this->joinStringWithNode('SHOW TABLES FROM', $node->args[0]->value);
}
return $node;
}
private function processMysqlCreateDb(\PhpParser\Node\Expr\FuncCall $funcCall) : \PhpParser\Node\Expr\FuncCall
private function processMysqlCreateDb(\PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr\FuncCall
{
if (!isset($funcCall->args[0])) {
return null;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$funcCall->name = new \PhpParser\Node\Name(self::MYSQLI_QUERY);
$funcCall->args[0]->value = $this->joinStringWithNode('CREATE DATABASE', $funcCall->args[0]->value);
return $funcCall;
}
private function processMysqlDropDb(\PhpParser\Node\Expr\FuncCall $funcCall) : \PhpParser\Node\Expr\FuncCall
private function processMysqlDropDb(\PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr\FuncCall
{
if (!isset($funcCall->args[0])) {
return null;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$funcCall->name = new \PhpParser\Node\Name(self::MYSQLI_QUERY);
$funcCall->args[0]->value = $this->joinStringWithNode('DROP DATABASE', $funcCall->args[0]->value);
return $funcCall;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\MysqlToMysqli\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\FuncCall;
@ -55,6 +56,12 @@ CODE_SAMPLE
if (!$this->isName($node, 'mysql_pconnect')) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$node->name = new \PhpParser\Node\Name('mysqli_connect');
$node->args[0]->value = $this->joinStringWithNode('p:', $node->args[0]->value);
return $node;

View File

@ -80,13 +80,14 @@ CODE_SAMPLE
if (!$this->isName($node, $oldFunction)) {
continue;
}
if ($node->args === [] || !$this->isProbablyMysql($node->args[0]->value)) {
$args = $node->getArgs();
if ($args === [] || !$this->isProbablyMysql($args[0]->value)) {
$connectionVariable = $this->findConnectionVariable($node);
$this->removeExistingConnectionParameter($node);
if (!$connectionVariable instanceof \PhpParser\Node\Expr) {
return null;
}
$node->args = \array_merge([new \PhpParser\Node\Arg($connectionVariable)], $node->args);
$node->args = \array_merge([new \PhpParser\Node\Arg($connectionVariable)], $node->getArgs());
}
$node->name = new \PhpParser\Node\Name($newFunction);
return $node;

View File

@ -197,6 +197,12 @@ final class VariableNaming
}
private function resolveBareFuncCallArgumentName(\PhpParser\Node\Expr\FuncCall $funcCall, string $fallbackName, string $suffix) : string
{
if (!isset($funcCall->args[0])) {
return '';
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return '';
}
$argumentValue = $funcCall->args[0]->value;
if ($argumentValue instanceof \PhpParser\Node\Expr\MethodCall || $argumentValue instanceof \PhpParser\Node\Expr\StaticCall) {
$name = $this->nodeNameResolver->getName($argumentValue->name);

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php53\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\MagicConst\Dir;
use PhpParser\Node\Scalar\MagicConst\File;
@ -57,6 +58,12 @@ CODE_SAMPLE
if (\count($node->args) !== 1) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$firstArgValue = $node->args[0]->value;
if (!$firstArgValue instanceof \PhpParser\Node\Scalar\MagicConst\File) {
return null;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php54\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
@ -54,6 +55,9 @@ CODE_SAMPLE
public function refactor(\PhpParser\Node $node) : \PhpParser\Node\Expr\FuncCall
{
foreach ($node->args as $nodeArg) {
if (!$nodeArg instanceof \PhpParser\Node\Arg) {
continue;
}
if ($nodeArg->byRef) {
$nodeArg->byRef = \false;
}

View File

@ -4,10 +4,12 @@ declare (strict_types=1);
namespace Rector\Php55\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php55\RegexMatcher;
@ -30,10 +32,15 @@ final class PregReplaceEModifierRector extends \Rector\Core\Rector\AbstractRecto
* @var \Rector\Php55\RegexMatcher
*/
private $regexMatcher;
public function __construct(\Rector\Php72\NodeFactory\AnonymousFunctionFactory $anonymousFunctionFactory, \Rector\Php55\RegexMatcher $regexMatcher)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Php72\NodeFactory\AnonymousFunctionFactory $anonymousFunctionFactory, \Rector\Php55\RegexMatcher $regexMatcher, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->anonymousFunctionFactory = $anonymousFunctionFactory;
$this->regexMatcher = $regexMatcher;
$this->argsAnalyzer = $argsAnalyzer;
}
public function provideMinPhpVersion() : int
{
@ -78,19 +85,26 @@ CODE_SAMPLE
if (!$this->isName($node, 'preg_replace')) {
return null;
}
$firstArgumentValue = $node->args[0]->value;
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($node->args, [0, 1])) {
return null;
}
/** @var Arg $firstArgument */
$firstArgument = $node->args[0];
$firstArgumentValue = $firstArgument->value;
$patternWithoutE = $this->regexMatcher->resolvePatternExpressionWithoutEIfFound($firstArgumentValue);
if (!$patternWithoutE instanceof \PhpParser\Node\Expr) {
return null;
}
$secondArgumentValue = $node->args[1]->value;
/** @var Arg $secondArgument */
$secondArgument = $node->args[1];
$secondArgumentValue = $secondArgument->value;
$anonymousFunction = $this->anonymousFunctionFactory->createAnonymousFunctionFromString($secondArgumentValue);
if (!$anonymousFunction instanceof \PhpParser\Node\Expr\Closure) {
return null;
}
$node->name = new \PhpParser\Node\Name('preg_replace_callback');
$node->args[0]->value = $patternWithoutE;
$node->args[1]->value = $anonymousFunction;
$firstArgument->value = $patternWithoutE;
$secondArgument->value = $anonymousFunction;
return $node;
}
}

View File

@ -4,8 +4,10 @@ declare (strict_types=1);
namespace Rector\Php56\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp\Pow;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
@ -16,6 +18,14 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class PowToExpRector extends \Rector\Core\Rector\AbstractRector implements \Rector\VersionBonding\Contract\MinPhpVersionInterface
{
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Changes pow(val, val2) to ** (exp) parameter', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample('pow(1, 2);', '1**2;')]);
@ -38,9 +48,14 @@ final class PowToExpRector extends \Rector\Core\Rector\AbstractRector implements
if (\count($node->args) !== 2) {
return null;
}
$firstArgument = $node->args[0]->value;
$secondArgument = $node->args[1]->value;
return new \PhpParser\Node\Expr\BinaryOp\Pow($firstArgument, $secondArgument);
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($node->args, [0, 1])) {
return null;
}
/** @var Arg $firstArgument */
$firstArgument = $node->args[0];
/** @var Arg $secondArgument */
$secondArgument = $node->args[1];
return new \PhpParser\Node\Expr\BinaryOp\Pow($firstArgument->value, $secondArgument->value);
}
public function provideMinPhpVersion() : int
{

View File

@ -46,7 +46,7 @@ final class CallUserMethodRector extends \Rector\Core\Rector\AbstractRector impl
}
$newName = self::OLD_TO_NEW_FUNCTIONS[$this->getName($node)];
$node->name = new \PhpParser\Node\Name($newName);
$oldArgs = $node->args;
$oldArgs = $node->getArgs();
unset($node->args[1]);
$newArgs = [$this->nodeFactory->createArg([$oldArgs[1]->value, $oldArgs[0]->value])];
unset($oldArgs[0]);

View File

@ -14,6 +14,7 @@ use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\Node\AttributeKey;
@ -36,9 +37,14 @@ final class EregToPregMatchRector extends \Rector\Core\Rector\AbstractRector imp
* @var \Rector\Php70\EregToPcreTransformer
*/
private $eregToPcreTransformer;
public function __construct(\Rector\Php70\EregToPcreTransformer $eregToPcreTransformer)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Php70\EregToPcreTransformer $eregToPcreTransformer, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->eregToPcreTransformer = $eregToPcreTransformer;
$this->argsAnalyzer = $argsAnalyzer;
}
public function provideMinPhpVersion() : int
{
@ -55,19 +61,30 @@ final class EregToPregMatchRector extends \Rector\Core\Rector\AbstractRector imp
{
return [\PhpParser\Node\Expr\FuncCall::class];
}
private function shouldSkip(\PhpParser\Node\Expr\FuncCall $funcCall) : bool
{
$functionName = $this->getName($funcCall);
if ($functionName === null) {
return \true;
}
if (!isset(self::OLD_NAMES_TO_NEW_ONES[$functionName])) {
return \true;
}
return !$this->argsAnalyzer->isArgInstanceInArgsPosition($funcCall->args, 0);
}
/**
* @param FuncCall $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if ($this->shouldSkip($node)) {
return null;
}
/** @var string $functionName */
$functionName = $this->getName($node);
if ($functionName === null) {
return null;
}
if (!isset(self::OLD_NAMES_TO_NEW_ONES[$functionName])) {
return null;
}
$patternNode = $node->args[0]->value;
/** @var Arg $firstArg */
$firstArg = $node->args[0];
$patternNode = $firstArg->value;
if ($patternNode instanceof \PhpParser\Node\Scalar\String_) {
$this->processStringPattern($node, $patternNode, $functionName);
} elseif ($patternNode instanceof \PhpParser\Node\Expr\Variable) {
@ -76,7 +93,7 @@ final class EregToPregMatchRector extends \Rector\Core\Rector\AbstractRector imp
$this->processSplitLimitArgument($node, $functionName);
$node->name = new \PhpParser\Node\Name(self::OLD_NAMES_TO_NEW_ONES[$functionName]);
// ereg|eregi 3rd argument return value fix
if (\in_array($functionName, ['ereg', 'eregi'], \true) && isset($node->args[2])) {
if (\in_array($functionName, ['ereg', 'eregi'], \true) && isset($node->args[2]) && $node->args[2] instanceof \PhpParser\Node\Arg) {
$parentNode = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
if ($parentNode instanceof \PhpParser\Node\Expr\Assign) {
return $this->createTernaryWithStrlenOfFirstMatch($node);
@ -88,7 +105,9 @@ final class EregToPregMatchRector extends \Rector\Core\Rector\AbstractRector imp
{
$pattern = $string->value;
$pattern = $this->eregToPcreTransformer->transform($pattern, $this->isCaseInsensitiveFunction($functionName));
$funcCall->args[0]->value = new \PhpParser\Node\Scalar\String_($pattern);
/** @var Arg $arg */
$arg = $funcCall->args[0];
$arg->value = new \PhpParser\Node\Scalar\String_($pattern);
}
private function processVariablePattern(\PhpParser\Node\Expr\FuncCall $funcCall, \PhpParser\Node\Expr\Variable $variable, string $functionName) : void
{
@ -96,7 +115,9 @@ final class EregToPregMatchRector extends \Rector\Core\Rector\AbstractRector imp
$startConcat = new \PhpParser\Node\Expr\BinaryOp\Concat(new \PhpParser\Node\Scalar\String_('#'), $pregQuotePatternNode);
$endDelimiter = $this->isCaseInsensitiveFunction($functionName) ? '#mi' : '#m';
$concat = new \PhpParser\Node\Expr\BinaryOp\Concat($startConcat, new \PhpParser\Node\Scalar\String_($endDelimiter));
$funcCall->args[0]->value = $concat;
/** @var Arg $arg */
$arg = $funcCall->args[0];
$arg->value = $concat;
}
/**
* Equivalent of:
@ -106,6 +127,12 @@ final class EregToPregMatchRector extends \Rector\Core\Rector\AbstractRector imp
*/
private function processSplitLimitArgument(\PhpParser\Node\Expr\FuncCall $funcCall, string $functionName) : void
{
if (!isset($funcCall->args[2])) {
return;
}
if (!$funcCall->args[2] instanceof \PhpParser\Node\Arg) {
return;
}
if (\strncmp($functionName, 'split', \strlen('split')) !== 0) {
return;
}
@ -125,7 +152,9 @@ final class EregToPregMatchRector extends \Rector\Core\Rector\AbstractRector imp
}
private function createTernaryWithStrlenOfFirstMatch(\PhpParser\Node\Expr\FuncCall $funcCall) : \PhpParser\Node\Expr\Ternary
{
$arrayDimFetch = new \PhpParser\Node\Expr\ArrayDimFetch($funcCall->args[2]->value, new \PhpParser\Node\Scalar\LNumber(0));
/** @var Arg $thirdArg */
$thirdArg = $funcCall->args[2];
$arrayDimFetch = new \PhpParser\Node\Expr\ArrayDimFetch($thirdArg->value, new \PhpParser\Node\Scalar\LNumber(0));
$strlenFuncCall = $this->nodeFactory->createFuncCall('strlen', [$arrayDimFetch]);
return new \PhpParser\Node\Expr\Ternary($funcCall, $strlenFuncCall, $this->nodeFactory->createFalse());
}

View File

@ -67,21 +67,22 @@ final class MultiDirnameRector extends \Rector\Core\Rector\AbstractRector implem
if (!$this->isName($funcCall, self::DIRNAME)) {
return null;
}
if (\count($funcCall->args) >= 3) {
$args = $funcCall->getArgs();
if (\count($args) >= 3) {
return null;
}
// dirname($path, <LEVEL>);
if (\count($funcCall->args) === 2) {
if (!$funcCall->args[1]->value instanceof \PhpParser\Node\Scalar\LNumber) {
if (\count($args) === 2) {
if (!$args[1]->value instanceof \PhpParser\Node\Scalar\LNumber) {
return null;
}
/** @var LNumber $levelNumber */
$levelNumber = $funcCall->args[1]->value;
$levelNumber = $args[1]->value;
$this->nestingLevel += $levelNumber->value;
} else {
++$this->nestingLevel;
}
$nestedFuncCallNode = $funcCall->args[0]->value;
$nestedFuncCallNode = $args[0]->value;
if (!$nestedFuncCallNode instanceof \PhpParser\Node\Expr\FuncCall) {
return null;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php70\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
@ -20,6 +21,7 @@ use PHPStan\Analyser\MutatingScope;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ParameterReflection;
use PHPStan\Type\MixedType;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\PhpVersionFeature;
@ -49,11 +51,16 @@ final class NonVariableToVariableOnFunctionCallRector extends \Rector\Core\Recto
* @var \Rector\Core\Reflection\ReflectionResolver
*/
private $reflectionResolver;
public function __construct(\Rector\Naming\Naming\VariableNaming $variableNaming, \Rector\NodeNestingScope\ParentScopeFinder $parentScopeFinder, \Rector\Core\Reflection\ReflectionResolver $reflectionResolver)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Naming\Naming\VariableNaming $variableNaming, \Rector\NodeNestingScope\ParentScopeFinder $parentScopeFinder, \Rector\Core\Reflection\ReflectionResolver $reflectionResolver, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->variableNaming = $variableNaming;
$this->parentScopeFinder = $parentScopeFinder;
$this->reflectionResolver = $reflectionResolver;
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -88,6 +95,9 @@ final class NonVariableToVariableOnFunctionCallRector extends \Rector\Core\Recto
return null;
}
foreach ($arguments as $key => $argument) {
if (!$node->args[$key] instanceof \PhpParser\Node\Arg) {
continue;
}
$replacements = $this->getReplacementsFor($argument, $currentScope, $scopeNode);
$current = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
$currentStatement = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
@ -114,13 +124,15 @@ final class NonVariableToVariableOnFunctionCallRector extends \Rector\Core\Recto
/** @var ParameterReflection $parameterReflection */
foreach ($parametersAcceptor->getParameters() as $key => $parameterReflection) {
// omitted optional parameter
if (!isset($call->args[$key])) {
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($call->args, $key)) {
continue;
}
if ($parameterReflection->passedByReference()->no()) {
continue;
}
$argument = $call->args[$key]->value;
/** @var Arg $arg */
$arg = $call->args[$key];
$argument = $arg->value;
if ($this->isVariableLikeNode($argument)) {
continue;
}

View File

@ -48,6 +48,12 @@ final class IsArrayAndDualCheckToAble
if (!$this->nodeNameResolver->isName($funcCall, 'is_array')) {
return null;
}
if (!isset($funcCall->args[0])) {
return null;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
// both use same var
if (!$funcCall->args[0]->value instanceof \PhpParser\Node\Expr\Variable) {
return null;

View File

@ -82,7 +82,9 @@ CODE_SAMPLE
if ($this->shouldSkip($node)) {
return null;
}
$countedNode = $node->args[0]->value;
/** @var Arg $arg0 */
$arg0 = $node->args[0];
$countedNode = $arg0->value;
if ($this->countableTypeAnalyzer->isCountableType($countedNode)) {
return null;
}
@ -122,6 +124,9 @@ CODE_SAMPLE
if (!isset($funcCall->args[0])) {
return \true;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return \true;
}
if ($funcCall->args[0]->value instanceof \PhpParser\Node\Expr\ClassConstFetch) {
return \true;
}

View File

@ -5,6 +5,7 @@ namespace Rector\Php72\NodeFactory;
use RectorPrefix20210927\Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\ComplexType;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
@ -84,7 +85,7 @@ final class AnonymousFunctionFactory
/**
* @param Param[] $params
* @param Stmt[] $stmts
* @param \PhpParser\Node\Identifier|\PhpParser\Node\Name|\PhpParser\Node\NullableType|\PhpParser\Node\UnionType|null $returnTypeNode
* @param \PhpParser\Node\Identifier|\PhpParser\Node\Name|\PhpParser\Node\NullableType|\PhpParser\Node\UnionType|\PhpParser\Node\ComplexType|null $returnTypeNode
*/
public function create(array $params, array $stmts, $returnTypeNode) : \PhpParser\Node\Expr\Closure
{

View File

@ -64,6 +64,12 @@ CODE_SAMPLE
}
/** @var FuncCall $eachFuncCall */
$eachFuncCall = $node->expr;
if (!isset($eachFuncCall->args[0])) {
return null;
}
if (!$eachFuncCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$eachedVariable = $eachFuncCall->args[0]->value;
$assignVariable = $node->var;
$newNodes = $this->createNewNodes($assignVariable, $eachedVariable);

View File

@ -17,6 +17,7 @@ use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Php\ReservedKeywordAnalyzer;
use Rector\Core\PhpParser\Parser\InlineCodeParser;
use Rector\Core\Rector\AbstractRector;
@ -44,11 +45,16 @@ final class CreateFunctionToAnonymousFunctionRector extends \Rector\Core\Rector\
* @var \Rector\Core\Php\ReservedKeywordAnalyzer
*/
private $reservedKeywordAnalyzer;
public function __construct(\Rector\Core\PhpParser\Parser\InlineCodeParser $inlineCodeParser, \Rector\Php72\NodeFactory\AnonymousFunctionFactory $anonymousFunctionFactory, \Rector\Core\Php\ReservedKeywordAnalyzer $reservedKeywordAnalyzer)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\PhpParser\Parser\InlineCodeParser $inlineCodeParser, \Rector\Php72\NodeFactory\AnonymousFunctionFactory $anonymousFunctionFactory, \Rector\Core\Php\ReservedKeywordAnalyzer $reservedKeywordAnalyzer, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->inlineCodeParser = $inlineCodeParser;
$this->anonymousFunctionFactory = $anonymousFunctionFactory;
$this->reservedKeywordAnalyzer = $reservedKeywordAnalyzer;
$this->argsAnalyzer = $argsAnalyzer;
}
public function provideMinPhpVersion() : int
{
@ -94,8 +100,15 @@ CODE_SAMPLE
if (!$this->isName($node, 'create_function')) {
return null;
}
$params = $this->createParamsFromString($node->args[0]->value);
$stmts = $this->parseStringToBody($node->args[1]->value);
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($node->args, [0, 1])) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $node->args[0];
/** @var Arg $secondArg */
$secondArg = $node->args[1];
$params = $this->createParamsFromString($firstArg->value);
$stmts = $this->parseStringToBody($secondArg->value);
$refactored = $this->anonymousFunctionFactory->create($params, $stmts, null);
foreach ($refactored->uses as $key => $use) {
$variableName = $this->getName($use->var);

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php72\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\FuncCall;
@ -67,6 +68,12 @@ CODE_SAMPLE
if (!$this->isName($node, 'get_class')) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$firstArgValue = $node->args[0]->value;
// only relevant inside the class
$scope = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
@ -121,6 +128,12 @@ CODE_SAMPLE
if (!$ternary->cond instanceof \PhpParser\Node\Expr\BinaryOp\Identical) {
return \false;
}
if (!isset($funcCall->args[0])) {
return \false;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return \false;
}
if ($this->nodeComparator->areNodesEqual($ternary->cond->left, $funcCall->args[0]->value) && !$this->valueResolver->isNull($ternary->cond->right)) {
return \true;
}
@ -137,6 +150,12 @@ CODE_SAMPLE
if (!$ternary->cond instanceof \PhpParser\Node\Expr\BinaryOp\NotIdentical) {
return \false;
}
if (!isset($funcCall->args[0])) {
return \false;
}
if (!$funcCall->args[0] instanceof \PhpParser\Node\Arg) {
return \false;
}
if ($this->nodeComparator->areNodesEqual($ternary->cond->left, $funcCall->args[0]->value) && $this->valueResolver->isNull($ternary->cond->right)) {
return \true;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php72\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\FuncCall;
use PHPStan\Type\ObjectType;
@ -52,6 +53,12 @@ CODE_SAMPLE
return null;
}
$incompleteClassObjectType = new \PHPStan\Type\ObjectType('__PHP_Incomplete_Class');
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
if (!$this->isObjectType($node->args[0]->value, $incompleteClassObjectType)) {
return null;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php72\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
@ -70,6 +71,12 @@ CODE_SAMPLE
if (!$this->isName($node, 'define')) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
if ($this->stringTypeAnalyzer->isStringOrUnionStringOnlyType($node->args[0]->value)) {
return null;
}

View File

@ -66,6 +66,9 @@ CODE_SAMPLE
if (!$this->isName($node, 'assert')) {
return null;
}
if (!$node->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
if (!$node->args[0]->value instanceof \PhpParser\Node\Scalar\String_) {
return null;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php72\Rector\While_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
@ -83,6 +84,12 @@ CODE_SAMPLE
$eachFuncCall = $assignNode->expr;
/** @var List_ $listNode */
$listNode = $assignNode->var;
if (!isset($eachFuncCall->args[0])) {
return null;
}
if (!$eachFuncCall->args[0] instanceof \PhpParser\Node\Arg) {
return null;
}
$foreachedExpr = \count($listNode->items) === 1 ? $this->nodeFactory->createFuncCall('array_keys', [$eachFuncCall->args[0]]) : $eachFuncCall->args[0]->value;
/** @var ArrayItem $arrayItem */
$arrayItem = \array_pop($listNode->items);

View File

@ -77,11 +77,11 @@ CODE_SAMPLE
if ($argsCount <= 2) {
return \true;
}
if ($funcCall->args[2]->value instanceof \PhpParser\Node\Expr\Array_) {
if ($funcCall->args[2] instanceof \PhpParser\Node\Arg && $funcCall->args[2]->value instanceof \PhpParser\Node\Expr\Array_) {
return \true;
}
if ($argsCount === 3) {
return $funcCall->args[2]->value instanceof \PhpParser\Node\Expr\Variable;
return $funcCall->args[2] instanceof \PhpParser\Node\Arg && $funcCall->args[2]->value instanceof \PhpParser\Node\Expr\Variable;
}
return \false;
}
@ -91,7 +91,7 @@ CODE_SAMPLE
private function composeNewArgs(\PhpParser\Node\Expr\FuncCall $funcCall) : array
{
$items = [];
$args = $funcCall->args;
$args = $funcCall->getArgs();
$newArgs = [];
$newArgs[] = $args[0];
$newArgs[] = $args[1];

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php73\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Cast\String_;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Rector\AbstractRector;
@ -61,6 +62,12 @@ CODE_SAMPLE
if (!$this->isNames($node, self::NEEDLE_STRING_SENSITIVE_FUNCTIONS)) {
return null;
}
if (!isset($node->args[1])) {
return null;
}
if (!$node->args[1] instanceof \PhpParser\Node\Arg) {
return null;
}
// is argument string?
$needleArgNode = $node->args[1]->value;
if ($this->nodeTypeAnalyzer->isStringTypeExpr($needleArgNode)) {

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php74\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PHPStan\Type\ObjectType;
@ -60,6 +61,12 @@ CODE_SAMPLE
if (!$this->isName($node, 'array_key_exists')) {
return null;
}
if (!isset($node->args[1])) {
return null;
}
if (!$node->args[1] instanceof \PhpParser\Node\Arg) {
return null;
}
$firstArgStaticType = $this->getStaticType($node->args[1]->value);
if (!$firstArgStaticType instanceof \PHPStan\Type\ObjectType) {
return null;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php74\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
@ -92,6 +93,9 @@ CODE_SAMPLE
{
$array = new \PhpParser\Node\Expr\Array_();
foreach ($funcCall->args as $arg) {
if (!$arg instanceof \PhpParser\Node\Arg) {
continue;
}
// cannot handle unpacked arguments
if ($arg->unpack) {
return null;
@ -124,8 +128,10 @@ CODE_SAMPLE
private function resolveValue(\PhpParser\Node\Expr $expr) : \PhpParser\Node\Expr
{
if ($expr instanceof \PhpParser\Node\Expr\FuncCall && $this->isIteratorToArrayFuncCall($expr)) {
/** @var Arg $arg */
$arg = $expr->args[0];
/** @var FuncCall $expr */
$expr = $expr->args[0]->value;
$expr = $arg->value;
}
if (!$expr instanceof \PhpParser\Node\Expr\Ternary) {
return $expr;
@ -163,6 +169,12 @@ CODE_SAMPLE
if (!$expr instanceof \PhpParser\Node\Expr\FuncCall) {
return \false;
}
return $this->nodeNameResolver->isName($expr, 'iterator_to_array');
if (!$this->nodeNameResolver->isName($expr, 'iterator_to_array')) {
return \false;
}
if (!isset($expr->args[0])) {
return \false;
}
return $expr->args[0] instanceof \PhpParser\Node\Arg;
}
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Php74\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use Rector\Core\Rector\AbstractRector;
@ -52,6 +53,9 @@ CODE_SAMPLE
if (!isset($node->args[1])) {
return null;
}
if (!$node->args[1] instanceof \PhpParser\Node\Arg) {
return null;
}
if (!$this->isName($node->args[1]->value, 'FILTER_SANITIZE_MAGIC_QUOTES')) {
return null;
}

View File

@ -49,6 +49,9 @@ final class MbStrrposEncodingArgumentPositionRector extends \Rector\Core\Rector\
if (isset($node->args[3])) {
return null;
}
if (!$node->args[2] instanceof \PhpParser\Node\Arg) {
return null;
}
$secondArgType = $this->getStaticType($node->args[2]->value);
if ($secondArgType instanceof \PHPStan\Type\IntegerType) {
return null;

View File

@ -10,6 +10,7 @@ use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PHPStan\Type\ObjectType;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
@ -22,6 +23,14 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class ExportToReflectionFunctionRector extends \Rector\Core\Rector\AbstractRector implements \Rector\VersionBonding\Contract\MinPhpVersionInterface
{
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
public function provideMinPhpVersion() : int
{
return \Rector\Core\ValueObject\PhpVersionFeature::EXPORT_TO_REFLECTION_FUNCTION;
@ -60,8 +69,18 @@ CODE_SAMPLE
if (!$this->isName($node->name, 'export')) {
return null;
}
$new = new \PhpParser\Node\Expr\New_($node->class, [new \PhpParser\Node\Arg($node->args[0]->value)]);
if (isset($node->args[1]) && $this->valueResolver->isTrue($node->args[1]->value)) {
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->args, 0)) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $node->args[0];
$new = new \PhpParser\Node\Expr\New_($node->class, [new \PhpParser\Node\Arg($firstArg->value)]);
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->args, 1)) {
return $new;
}
/** @var Arg $secondArg */
$secondArg = $node->args[1];
if ($this->valueResolver->isTrue($secondArg->value)) {
return new \PhpParser\Node\Expr\Cast\String_($new);
}
return $new;

View File

@ -4,12 +4,14 @@ declare (strict_types=1);
namespace Rector\Php80\MatchAndRefactor\StrStartsWithMatchAndRefactor;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\Php80\Contract\StrStartWithMatchAndRefactorInterface;
@ -38,12 +40,17 @@ final class StrncmpMatchAndRefactor implements \Rector\Php80\Contract\StrStartWi
* @var \Rector\Php80\NodeFactory\StrStartsWithFuncCallFactory
*/
private $strStartsWithFuncCallFactory;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Php80\ValueObjectFactory\StrStartsWithFactory $strStartsWithFactory, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator, \Rector\Php80\NodeFactory\StrStartsWithFuncCallFactory $strStartsWithFuncCallFactory)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Php80\ValueObjectFactory\StrStartsWithFactory $strStartsWithFactory, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator, \Rector\Php80\NodeFactory\StrStartsWithFuncCallFactory $strStartsWithFuncCallFactory, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->strStartsWithFactory = $strStartsWithFactory;
$this->nodeComparator = $nodeComparator;
$this->strStartsWithFuncCallFactory = $strStartsWithFuncCallFactory;
$this->argsAnalyzer = $argsAnalyzer;
}
/**
* @param Identical|NotIdentical $binaryOp
@ -79,7 +86,12 @@ final class StrncmpMatchAndRefactor implements \Rector\Php80\Contract\StrStartWi
{
$strncmpFuncCall = $strStartsWith->getFuncCall();
$needleExpr = $strStartsWith->getNeedleExpr();
$secondArgumentValue = $strncmpFuncCall->args[2]->value;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($strncmpFuncCall->args, 2)) {
return \false;
}
/** @var Arg $thirdArg */
$thirdArg = $strncmpFuncCall->args[2];
$secondArgumentValue = $thirdArg->value;
if (!$secondArgumentValue instanceof \PhpParser\Node\Expr\FuncCall) {
return \false;
}
@ -87,18 +99,30 @@ final class StrncmpMatchAndRefactor implements \Rector\Php80\Contract\StrStartWi
return \false;
}
/** @var FuncCall $strlenFuncCall */
$strlenFuncCall = $strncmpFuncCall->args[2]->value;
$strlenArgumentValue = $strlenFuncCall->args[0]->value;
$strlenFuncCall = $thirdArg->value;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($strlenFuncCall->args, 0)) {
return \false;
}
/** @var Arg $firstArg */
$firstArg = $strlenFuncCall->args[0];
$strlenArgumentValue = $firstArg->value;
return $this->nodeComparator->areNodesEqual($needleExpr, $strlenArgumentValue);
}
private function isHardcodedStringWithLNumberLength(\Rector\Php80\ValueObject\StrStartsWith $strStartsWith) : bool
{
$strncmpFuncCall = $strStartsWith->getFuncCall();
$hardcodedStringNeedle = $strncmpFuncCall->args[1]->value;
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($strncmpFuncCall->args, [1, 2])) {
return \false;
}
/** @var Arg $secondArg */
$secondArg = $strncmpFuncCall->args[1];
$hardcodedStringNeedle = $secondArg->value;
if (!$hardcodedStringNeedle instanceof \PhpParser\Node\Scalar\String_) {
return \false;
}
$lNumberLength = $strncmpFuncCall->args[2]->value;
/** @var Arg $thirdArg */
$thirdArg = $strncmpFuncCall->args[2];
$lNumberLength = $thirdArg->value;
if (!$lNumberLength instanceof \PhpParser\Node\Scalar\LNumber) {
return \false;
}

View File

@ -4,12 +4,14 @@ declare (strict_types=1);
namespace Rector\Php80\MatchAndRefactor\StrStartsWithMatchAndRefactor;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\Php80\Contract\StrStartWithMatchAndRefactorInterface;
@ -29,11 +31,16 @@ final class StrposMatchAndRefactor implements \Rector\Php80\Contract\StrStartWit
* @var \Rector\Php80\NodeFactory\StrStartsWithFuncCallFactory
*/
private $strStartsWithFuncCallFactory;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Core\PhpParser\Node\Value\ValueResolver $valueResolver, \Rector\Php80\NodeFactory\StrStartsWithFuncCallFactory $strStartsWithFuncCallFactory)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Core\PhpParser\Node\Value\ValueResolver $valueResolver, \Rector\Php80\NodeFactory\StrStartsWithFuncCallFactory $strStartsWithFuncCallFactory, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->valueResolver = $valueResolver;
$this->strStartsWithFuncCallFactory = $strStartsWithFuncCallFactory;
$this->argsAnalyzer = $argsAnalyzer;
}
/**
* @param Identical|NotIdentical $binaryOp
@ -42,26 +49,15 @@ final class StrposMatchAndRefactor implements \Rector\Php80\Contract\StrStartWit
{
$isPositive = $binaryOp instanceof \PhpParser\Node\Expr\BinaryOp\Identical;
if ($binaryOp->left instanceof \PhpParser\Node\Expr\FuncCall && $this->nodeNameResolver->isName($binaryOp->left, 'strpos')) {
if (!$this->valueResolver->isValue($binaryOp->right, 0)) {
return null;
}
/** @var FuncCall $funcCall */
$funcCall = $binaryOp->left;
$haystack = $funcCall->args[0]->value;
$needle = $funcCall->args[1]->value;
return new \Rector\Php80\ValueObject\StrStartsWith($funcCall, $haystack, $needle, $isPositive);
return $this->processBinaryOpLeft($binaryOp, $isPositive);
}
if ($binaryOp->right instanceof \PhpParser\Node\Expr\FuncCall && $this->nodeNameResolver->isName($binaryOp->right, 'strpos')) {
if (!$this->valueResolver->isValue($binaryOp->left, 0)) {
return null;
}
/** @var FuncCall $funcCall */
$funcCall = $binaryOp->right;
$haystack = $funcCall->args[0]->value;
$needle = $funcCall->args[1]->value;
return new \Rector\Php80\ValueObject\StrStartsWith($funcCall, $haystack, $needle, $isPositive);
if (!$binaryOp->right instanceof \PhpParser\Node\Expr\FuncCall) {
return null;
}
return null;
if (!$this->nodeNameResolver->isName($binaryOp->right, 'strpos')) {
return null;
}
return $this->processBinaryOpRight($binaryOp, $isPositive);
}
/**
* @return FuncCall|BooleanNot
@ -73,4 +69,40 @@ final class StrposMatchAndRefactor implements \Rector\Php80\Contract\StrStartWit
$strposFuncCall->name = new \PhpParser\Node\Name('str_starts_with');
return $this->strStartsWithFuncCallFactory->createStrStartsWith($strStartsWith);
}
private function processBinaryOpLeft(\PhpParser\Node\Expr\BinaryOp $binaryOp, bool $isPositive) : ?\Rector\Php80\ValueObject\StrStartsWith
{
if (!$this->valueResolver->isValue($binaryOp->right, 0)) {
return null;
}
/** @var FuncCall $funcCall */
$funcCall = $binaryOp->left;
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($funcCall->args, [0, 1])) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $funcCall->args[0];
$haystack = $firstArg->value;
/** @var Arg $secondArg */
$secondArg = $funcCall->args[1];
$needle = $secondArg->value;
return new \Rector\Php80\ValueObject\StrStartsWith($funcCall, $haystack, $needle, $isPositive);
}
private function processBinaryOpRight(\PhpParser\Node\Expr\BinaryOp $binaryOp, bool $isPositive) : ?\Rector\Php80\ValueObject\StrStartsWith
{
if (!$this->valueResolver->isValue($binaryOp->left, 0)) {
return null;
}
/** @var FuncCall $funcCall */
$funcCall = $binaryOp->right;
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($funcCall->args, [0, 1])) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $funcCall->args[0];
$haystack = $firstArg->value;
/** @var Arg $secondArg */
$secondArg = $funcCall->args[1];
$needle = $secondArg->value;
return new \Rector\Php80\ValueObject\StrStartsWith($funcCall, $haystack, $needle, $isPositive);
}
}

View File

@ -4,12 +4,14 @@ declare (strict_types=1);
namespace Rector\Php80\MatchAndRefactor\StrStartsWithMatchAndRefactor;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\NodeNameResolver\NodeNameResolver;
@ -34,12 +36,17 @@ final class SubstrMatchAndRefactor implements \Rector\Php80\Contract\StrStartWit
* @var \Rector\Php80\NodeFactory\StrStartsWithFuncCallFactory
*/
private $strStartsWithFuncCallFactory;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Core\PhpParser\Node\Value\ValueResolver $valueResolver, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator, \Rector\Php80\NodeFactory\StrStartsWithFuncCallFactory $strStartsWithFuncCallFactory)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Core\PhpParser\Node\Value\ValueResolver $valueResolver, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator, \Rector\Php80\NodeFactory\StrStartsWithFuncCallFactory $strStartsWithFuncCallFactory, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->valueResolver = $valueResolver;
$this->nodeComparator = $nodeComparator;
$this->strStartsWithFuncCallFactory = $strStartsWithFuncCallFactory;
$this->argsAnalyzer = $argsAnalyzer;
}
/**
* @param Identical|NotIdentical $binaryOp
@ -50,13 +57,23 @@ final class SubstrMatchAndRefactor implements \Rector\Php80\Contract\StrStartWit
if ($binaryOp->left instanceof \PhpParser\Node\Expr\FuncCall && $this->nodeNameResolver->isName($binaryOp->left, 'substr')) {
/** @var FuncCall $funcCall */
$funcCall = $binaryOp->left;
$haystack = $funcCall->args[0]->value;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($funcCall->args, 0)) {
return null;
}
/** @var Arg $arg */
$arg = $funcCall->args[0];
$haystack = $arg->value;
return new \Rector\Php80\ValueObject\StrStartsWith($funcCall, $haystack, $binaryOp->right, $isPositive);
}
if ($binaryOp->right instanceof \PhpParser\Node\Expr\FuncCall && $this->nodeNameResolver->isName($binaryOp->right, 'substr')) {
/** @var FuncCall $funcCall */
$funcCall = $binaryOp->right;
$haystack = $funcCall->args[0]->value;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($funcCall->args, 0)) {
return null;
}
/** @var Arg $arg */
$arg = $funcCall->args[0];
$haystack = $arg->value;
return new \Rector\Php80\ValueObject\StrStartsWith($funcCall, $haystack, $binaryOp->left, $isPositive);
}
return null;
@ -77,10 +94,20 @@ final class SubstrMatchAndRefactor implements \Rector\Php80\Contract\StrStartWit
private function isStrlenWithNeedleExpr(\Rector\Php80\ValueObject\StrStartsWith $strStartsWith) : bool
{
$substrFuncCall = $strStartsWith->getFuncCall();
if (!$this->valueResolver->isValue($substrFuncCall->args[1]->value, 0)) {
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($substrFuncCall->args, 1)) {
return \false;
}
$secondFuncCallArgValue = $substrFuncCall->args[2]->value;
/** @var Arg $arg1 */
$arg1 = $substrFuncCall->args[1];
if (!$this->valueResolver->isValue($arg1->value, 0)) {
return \false;
}
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($substrFuncCall->args, 2)) {
return \false;
}
/** @var Arg $arg2 */
$arg2 = $substrFuncCall->args[2];
$secondFuncCallArgValue = $arg2->value;
if (!$secondFuncCallArgValue instanceof \PhpParser\Node\Expr\FuncCall) {
return \false;
}
@ -88,22 +115,37 @@ final class SubstrMatchAndRefactor implements \Rector\Php80\Contract\StrStartWit
return \false;
}
/** @var FuncCall $strlenFuncCall */
$strlenFuncCall = $substrFuncCall->args[2]->value;
$needleExpr = $strlenFuncCall->args[0]->value;
$strlenFuncCall = $arg2->value;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($strlenFuncCall->args, 0)) {
return \false;
}
/** @var Arg $arg0 */
$arg0 = $strlenFuncCall->args[0];
$needleExpr = $arg0->value;
$comparedNeedleExpr = $strStartsWith->getNeedleExpr();
return $this->nodeComparator->areNodesEqual($needleExpr, $comparedNeedleExpr);
}
private function isHardcodedStringWithLNumberLength(\Rector\Php80\ValueObject\StrStartsWith $strStartsWith) : bool
{
$substrFuncCall = $strStartsWith->getFuncCall();
if (!$this->valueResolver->isValue($substrFuncCall->args[1]->value, 0)) {
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($substrFuncCall->args, 1)) {
return \false;
}
/** @var Arg $arg1 */
$arg1 = $substrFuncCall->args[1];
if (!$this->valueResolver->isValue($arg1->value, 0)) {
return \false;
}
$hardcodedStringNeedle = $strStartsWith->getNeedleExpr();
if (!$hardcodedStringNeedle instanceof \PhpParser\Node\Scalar\String_) {
return \false;
}
$lNumberLength = $substrFuncCall->args[2]->value;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($substrFuncCall->args, 2)) {
return \false;
}
/** @var Arg $arg2 */
$arg2 = $substrFuncCall->args[2];
$lNumberLength = $arg2->value;
if (!$lNumberLength instanceof \PhpParser\Node\Scalar\LNumber) {
return \false;
}

View File

@ -18,6 +18,7 @@ use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\If_;
use PHPStan\Type\ArrayType;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\NodeNameResolver\NodeNameResolver;
@ -56,7 +57,11 @@ final class TokenManipulator
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
*/
private $nodeComparator;
public function __construct(\RectorPrefix20210927\Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser $simpleCallableNodeTraverser, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\NodeTypeResolver\NodeTypeResolver $nodeTypeResolver, \Rector\PostRector\Collector\NodesToRemoveCollector $nodesToRemoveCollector, \Rector\Core\PhpParser\Node\Value\ValueResolver $valueResolver, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator)
/**
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\RectorPrefix20210927\Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser $simpleCallableNodeTraverser, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\NodeTypeResolver\NodeTypeResolver $nodeTypeResolver, \Rector\PostRector\Collector\NodesToRemoveCollector $nodesToRemoveCollector, \Rector\Core\PhpParser\Node\Value\ValueResolver $valueResolver, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator, \Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
$this->nodeNameResolver = $nodeNameResolver;
@ -64,6 +69,7 @@ final class TokenManipulator
$this->nodesToRemoveCollector = $nodesToRemoveCollector;
$this->valueResolver = $valueResolver;
$this->nodeComparator = $nodeComparator;
$this->argsAnalyzer = $argsAnalyzer;
}
/**
* @param Node[] $nodes
@ -170,7 +176,12 @@ final class TokenManipulator
if (!$this->nodeNameResolver->isName($node, 'is_array')) {
return null;
}
if (!$this->nodeComparator->areNodesEqual($node->args[0]->value, $singleTokenVariable)) {
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->args, 0)) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $node->args[0];
if (!$this->nodeComparator->areNodesEqual($firstArg->value, $singleTokenVariable)) {
return null;
}
if ($this->shouldSkipNodeRemovalForPartOfIf($node)) {
@ -195,7 +206,12 @@ final class TokenManipulator
if (!$this->nodeNameResolver->isName($node, 'token_name')) {
return null;
}
$possibleTokenArray = $node->args[0]->value;
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->args, 0)) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $node->args[0];
$possibleTokenArray = $firstArg->value;
if (!$possibleTokenArray instanceof \PhpParser\Node\Expr\ArrayDimFetch) {
return null;
}

View File

@ -129,11 +129,11 @@ CODE_SAMPLE
if (!$methodReflection instanceof \PHPStan\Reflection\MethodReflection) {
return null;
}
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($methodReflection, $new->args);
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($methodReflection, $new->getArgs());
if ($expectedArgOrParamOrder === null) {
return null;
}
$new->args = $this->argumentSorter->sortArgsByExpectedParamOrder($new->args, $expectedArgOrParamOrder);
$new->args = $this->argumentSorter->sortArgsByExpectedParamOrder($new->getArgs(), $expectedArgOrParamOrder);
$new->setAttribute(self::ALREADY_SORTED, \true);
return $new;
}
@ -143,11 +143,11 @@ CODE_SAMPLE
if (!$methodReflection instanceof \PHPStan\Reflection\MethodReflection) {
return null;
}
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($methodReflection, $methodCall->args);
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($methodReflection, $methodCall->getArgs());
if ($expectedArgOrParamOrder === null) {
return null;
}
$newArgs = $this->argumentSorter->sortArgsByExpectedParamOrder($methodCall->args, $expectedArgOrParamOrder);
$newArgs = $this->argumentSorter->sortArgsByExpectedParamOrder($methodCall->getArgs(), $expectedArgOrParamOrder);
if ($methodCall->args === $newArgs) {
return null;
}

Some files were not shown because too many files have changed in this diff Show More