1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

->args to ->getArgs

This commit is contained in:
orklah 2021-10-09 23:37:04 +02:00
parent f62c76a334
commit 870ee4ff93
36 changed files with 291 additions and 274 deletions

View File

@ -31,7 +31,7 @@
"felixfbecker/advanced-json-rpc": "^3.0.3",
"felixfbecker/language-server-protocol": "^1.5",
"netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0",
"nikic/php-parser": "4.12.*",
"nikic/php-parser": "^4.13",
"openlss/lib-array2xml": "^1.0",
"sebastian/diff": "^3.0 || ^4.0",
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0",

View File

@ -442,24 +442,12 @@ return [
'reflectionparameter' => [
'name' => 'string',
],
'phpparser\\node\\expr\\funccall' => [
'args' => 'list<PhpParser\Node\Arg>',
],
'phpparser\\node\\expr\\new_' => [
'args' => 'list<PhpParser\Node\Arg>',
],
'phpparser\\node\\expr\\array_' => [
'items' => 'array<int, PhpParser\Node\Expr\ArrayItem|null>',
],
'phpparser\\node\\expr\\list_' => [
'items' => 'array<int, PhpParser\Node\Expr\ArrayItem|null>',
],
'phpparser\\node\\expr\\methodcall' => [
'args' => 'list<PhpParser\Node\Arg>',
],
'phpparser\\node\\expr\\staticcall' => [
'args' => 'list<PhpParser\Node\Arg>',
],
'phpparser\\node\\expr\\arrowfunction' => [
'params' => 'list<PhpParser\Node\Param>',
],

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@4602e4ae22563289b2f1810dd9129cd0a2c76123">
<files psalm-version="dev-master@f62c76a334982eae94741b966ea886f0b15e4293">
<file src="examples/TemplateChecker.php">
<PossiblyUndefinedIntArrayOffset occurrences="2">
<code>$comment_block-&gt;tags['variablesfrom'][0]</code>
@ -46,9 +46,6 @@
<PossiblyUndefinedIntArrayOffset occurrences="1">
<code>$line_parts[1]</code>
</PossiblyUndefinedIntArrayOffset>
<RedundantCondition occurrences="1">
<code>$line_parts</code>
</RedundantCondition>
</file>
<file src="src/Psalm/Internal/Analyzer/ProjectAnalyzer.php">
<PossiblyUndefinedIntArrayOffset occurrences="4">
@ -80,7 +77,7 @@
</file>
<file src="src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php">
<PossiblyUndefinedIntArrayOffset occurrences="3">
<code>$new_case_equality_expr-&gt;args[1]</code>
<code>$new_case_equality_expr-&gt;getArgs()[1]</code>
<code>$switch_scope-&gt;leftover_statements[0]</code>
<code>$traverser-&gt;traverse([$switch_condition])[0]</code>
</PossiblyUndefinedIntArrayOffset>
@ -91,30 +88,40 @@
</InvalidPropertyAssignmentValue>
</file>
<file src="src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php">
<PossiblyUndefinedIntArrayOffset occurrences="23">
<PossiblyUndefinedIntArrayOffset occurrences="33">
<code>$assertion-&gt;rule[0]</code>
<code>$assertion-&gt;rule[0]</code>
<code>$assertion-&gt;rule[0]</code>
<code>$assertion-&gt;rule[0]</code>
<code>$assertion-&gt;rule[0]</code>
<code>$assertion-&gt;rule[0]</code>
<code>$count_expr-&gt;args[0]</code>
<code>$count_expr-&gt;args[0]</code>
<code>$count_expr-&gt;args[0]</code>
<code>$count_expr-&gt;args[0]</code>
<code>$count_expr-&gt;args[0]</code>
<code>$counted_expr-&gt;args[0]</code>
<code>$expr-&gt;args[0]</code>
<code>$expr-&gt;args[0]</code>
<code>$expr-&gt;args[0]</code>
<code>$expr-&gt;args[0]</code>
<code>$expr-&gt;args[1]</code>
<code>$expr-&gt;args[1]</code>
<code>$get_debug_type_expr-&gt;args[0]</code>
<code>$get_debug_type_expr-&gt;args[0]</code>
<code>$getclass_expr-&gt;args[0]</code>
<code>$gettype_expr-&gt;args[0]</code>
<code>$gettype_expr-&gt;args[0]</code>
<code>$count_expr-&gt;getArgs()[0]</code>
<code>$count_expr-&gt;getArgs()[0]</code>
<code>$count_expr-&gt;getArgs()[0]</code>
<code>$count_expr-&gt;getArgs()[0]</code>
<code>$count_expr-&gt;getArgs()[0]</code>
<code>$counted_expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[1]</code>
<code>$expr-&gt;getArgs()[1]</code>
<code>$get_debug_type_expr-&gt;getArgs()[0]</code>
<code>$get_debug_type_expr-&gt;getArgs()[0]</code>
<code>$getclass_expr-&gt;getArgs()[0]</code>
<code>$gettype_expr-&gt;getArgs()[0]</code>
<code>$gettype_expr-&gt;getArgs()[0]</code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php">
@ -147,7 +154,7 @@
<file src="src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php">
<PossiblyUndefinedIntArrayOffset occurrences="2">
<code>$parts[1]</code>
<code>$stmt-&gt;args[0]</code>
<code>$stmt-&gt;getArgs()[0]</code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php">
@ -190,7 +197,7 @@
</file>
<file src="src/Psalm/Internal/Analyzer/StatementsAnalyzer.php">
<PossiblyUndefinedIntArrayOffset occurrences="1">
<code>$stmt-&gt;expr-&gt;args[0]</code>
<code>$stmt-&gt;expr-&gt;getArgs()[0]</code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/Codebase/InternalCallMapHandler.php">
@ -268,12 +275,9 @@
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php">
<PossiblyUndefinedIntArrayOffset occurrences="5">
<code>$node-&gt;args[0]</code>
<code>$node-&gt;args[0]</code>
<code>$node-&gt;args[1]</code>
<code>$node-&gt;args[1]</code>
<code>$node-&gt;args[1]</code>
<PossiblyUndefinedIntArrayOffset occurrences="2">
<code>$node-&gt;getArgs()[0]</code>
<code>$node-&gt;getArgs()[1]</code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php">

View File

@ -17,6 +17,9 @@
limitMethodComplexity="true"
errorBaseline="psalm-baseline.xml"
>
<stubs>
<file name="stubs/phpparser.phpstub"/>
</stubs>
<projectFiles>
<directory name="src"/>
<directory name="tests"/>

View File

@ -329,7 +329,7 @@ class ReturnTypeCollector
|| $stmt instanceof PhpParser\Node\Expr\StaticCall) {
$yield_types = [];
foreach ($stmt->args as $arg) {
foreach ($stmt->getArgs() as $arg) {
$yield_types = array_merge($yield_types, self::getYieldTypeFromExpression($arg->value, $nodes));
}

View File

@ -316,7 +316,7 @@ class SwitchCaseAnalyzer
if ($new_case_equality_expr) {
ExpressionAnalyzer::analyze(
$statements_analyzer,
$new_case_equality_expr->args[1]->value,
$new_case_equality_expr->getArgs()[1]->value,
$case_context
);

View File

@ -413,7 +413,7 @@ class AssertionFinder
/** @var PhpParser\Node\Expr\FuncCall $count_expr */
$var_name = ExpressionIdentifier::getArrayVarId(
$count_expr->args[0]->value,
$count_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -599,7 +599,7 @@ class AssertionFinder
/** @var PhpParser\Node\Expr\FuncCall $count_expr */
$var_name = ExpressionIdentifier::getArrayVarId(
$count_expr->args[0]->value,
$count_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -689,9 +689,9 @@ class AssertionFinder
?Codebase $codebase = null,
bool $negate = false
): array {
$first_var_name = isset($expr->args[0]->value)
$first_var_name = isset($expr->getArgs()[0]->value)
? ExpressionIdentifier::getArrayVarId(
$expr->args[0]->value,
$expr->getArgs()[0]->value,
$this_class_name,
$source
)
@ -699,9 +699,9 @@ class AssertionFinder
$if_types = [];
$first_var_type = isset($expr->args[0]->value)
$first_var_type = isset($expr->getArgs()[0]->value)
&& $source instanceof StatementsAnalyzer
? $source->node_data->getType($expr->args[0]->value)
? $source->node_data->getType($expr->getArgs()[0]->value)
: null;
if ($tmp_if_types = self::handleIsTypeCheck(
@ -719,18 +719,18 @@ class AssertionFinder
} elseif (self::hasCallableCheck($expr)) {
if ($first_var_name) {
$if_types[$first_var_name] = [['callable']];
} elseif ($expr->args[0]->value instanceof PhpParser\Node\Expr\Array_
&& isset($expr->args[0]->value->items[0], $expr->args[0]->value->items[1])
&& $expr->args[0]->value->items[1]->value instanceof PhpParser\Node\Scalar\String_
} elseif ($expr->getArgs()[0]->value instanceof PhpParser\Node\Expr\Array_
&& isset($expr->getArgs()[0]->value->items[0], $expr->getArgs()[0]->value->items[1])
&& $expr->getArgs()[0]->value->items[1]->value instanceof PhpParser\Node\Scalar\String_
) {
$first_var_name_in_array_argument = ExpressionIdentifier::getArrayVarId(
$expr->args[0]->value->items[0]->value,
$expr->getArgs()[0]->value->items[0]->value,
$this_class_name,
$source
);
if ($first_var_name_in_array_argument) {
$if_types[$first_var_name_in_array_argument] = [
['hasmethod-' . $expr->args[0]->value->items[1]->value->value]
['hasmethod-' . $expr->getArgs()[0]->value->items[1]->value->value]
];
}
}
@ -757,11 +757,11 @@ class AssertionFinder
}
} elseif ($expr->name instanceof PhpParser\Node\Name
&& strtolower($expr->name->parts[0]) === 'method_exists'
&& isset($expr->args[1])
&& $expr->args[1]->value instanceof PhpParser\Node\Scalar\String_
&& isset($expr->getArgs()[1])
&& $expr->getArgs()[1]->value instanceof PhpParser\Node\Scalar\String_
) {
if ($first_var_name) {
$if_types[$first_var_name] = [['hasmethod-' . $expr->args[1]->value->value]];
$if_types[$first_var_name] = [['hasmethod-' . $expr->getArgs()[1]->value->value]];
}
} elseif (self::hasInArrayCheck($expr) && $source instanceof StatementsAnalyzer) {
return self::getInarrayAssertions($expr, $source, $first_var_name);
@ -876,9 +876,9 @@ class AssertionFinder
return [];
}
$first_var_name = isset($expr->args[0]->value)
$first_var_name = isset($expr->getArgs()[0]->value)
? ExpressionIdentifier::getArrayVarId(
$expr->args[0]->value,
$expr->getArgs()[0]->value,
$this_class_name,
$source
)
@ -908,12 +908,12 @@ class AssertionFinder
}
}
if (is_int($assertion->var_id) && isset($expr->args[$assertion->var_id])) {
if (is_int($assertion->var_id) && isset($expr->getArgs()[$assertion->var_id])) {
if ($assertion->var_id === 0) {
$var_name = $first_var_name;
} else {
$var_name = ExpressionIdentifier::getArrayVarId(
$expr->args[$assertion->var_id]->value,
$expr->getArgs()[$assertion->var_id]->value,
$this_class_name,
$source
);
@ -973,12 +973,12 @@ class AssertionFinder
}
}
if (is_int($assertion->var_id) && isset($expr->args[$assertion->var_id])) {
if (is_int($assertion->var_id) && isset($expr->getArgs()[$assertion->var_id])) {
if ($assertion->var_id === 0) {
$var_name = $first_var_name;
} else {
$var_name = ExpressionIdentifier::getArrayVarId(
$expr->args[$assertion->var_id]->value,
$expr->getArgs()[$assertion->var_id]->value,
$this_class_name,
$source
);
@ -1183,7 +1183,7 @@ class AssertionFinder
if ($conditional->right instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->right->name instanceof PhpParser\Node\Name
&& strtolower($conditional->right->name->parts[0]) === 'gettype'
&& $conditional->right->args
&& $conditional->right->getArgs()
&& $conditional->left instanceof PhpParser\Node\Scalar\String_
) {
return self::ASSIGNMENT_TO_RIGHT;
@ -1192,7 +1192,7 @@ class AssertionFinder
if ($conditional->left instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->left->name instanceof PhpParser\Node\Name
&& strtolower($conditional->left->name->parts[0]) === 'gettype'
&& $conditional->left->args
&& $conditional->left->getArgs()
&& $conditional->right instanceof PhpParser\Node\Scalar\String_
) {
return self::ASSIGNMENT_TO_LEFT;
@ -1211,7 +1211,7 @@ class AssertionFinder
if ($conditional->right instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->right->name instanceof PhpParser\Node\Name
&& strtolower($conditional->right->name->parts[0]) === 'get_debug_type'
&& $conditional->right->args
&& $conditional->right->getArgs()
&& ($conditional->left instanceof PhpParser\Node\Scalar\String_
|| $conditional->left instanceof PhpParser\Node\Expr\ClassConstFetch)
) {
@ -1221,7 +1221,7 @@ class AssertionFinder
if ($conditional->left instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->left->name instanceof PhpParser\Node\Name
&& strtolower($conditional->left->name->parts[0]) === 'get_debug_type'
&& $conditional->left->args
&& $conditional->left->getArgs()
&& ($conditional->right instanceof PhpParser\Node\Scalar\String_
|| $conditional->right instanceof PhpParser\Node\Expr\ClassConstFetch)
) {
@ -1321,7 +1321,7 @@ class AssertionFinder
$left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->left->name instanceof PhpParser\Node\Name
&& strtolower($conditional->left->name->parts[0]) === 'count'
&& $conditional->left->args;
&& $conditional->left->getArgs();
$operator_greater_than_or_equal =
$conditional instanceof PhpParser\Node\Expr\BinaryOp\Greater
@ -1345,7 +1345,7 @@ class AssertionFinder
$right_count = $conditional->right instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->right->name instanceof PhpParser\Node\Name
&& strtolower($conditional->right->name->parts[0]) === 'count'
&& $conditional->right->args;
&& $conditional->right->getArgs();
$operator_less_than_or_equal =
$conditional instanceof PhpParser\Node\Expr\BinaryOp\Smaller
@ -1378,7 +1378,7 @@ class AssertionFinder
$left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->left->name instanceof PhpParser\Node\Name
&& strtolower($conditional->left->name->parts[0]) === 'count'
&& $conditional->left->args;
&& $conditional->left->getArgs();
$operator_less_than_or_equal =
$conditional instanceof PhpParser\Node\Expr\BinaryOp\SmallerOrEqual
@ -1397,7 +1397,7 @@ class AssertionFinder
$right_count = $conditional->right instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->right->name instanceof PhpParser\Node\Name
&& strtolower($conditional->right->name->parts[0]) === 'count'
&& $conditional->right->args;
&& $conditional->right->getArgs();
$operator_greater_than_or_equal =
$conditional instanceof PhpParser\Node\Expr\BinaryOp\GreaterOrEqual
@ -1427,7 +1427,7 @@ class AssertionFinder
$left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->left->name instanceof PhpParser\Node\Name
&& strtolower($conditional->left->name->parts[0]) === 'count'
&& $conditional->left->args;
&& $conditional->left->getArgs();
if ($left_count && $conditional->right instanceof PhpParser\Node\Scalar\LNumber) {
$count = $conditional->right->value;
@ -1438,7 +1438,7 @@ class AssertionFinder
$right_count = $conditional->right instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->right->name instanceof PhpParser\Node\Name
&& strtolower($conditional->right->name->parts[0]) === 'count'
&& $conditional->right->args;
&& $conditional->right->getArgs();
if ($right_count && $conditional->left instanceof PhpParser\Node\Scalar\LNumber) {
$count = $conditional->left->value;
@ -1649,9 +1649,9 @@ class AssertionFinder
if ($stmt->name instanceof PhpParser\Node\Name
&& (strtolower($stmt->name->parts[0]) === 'is_a'
|| strtolower($stmt->name->parts[0]) === 'is_subclass_of')
&& isset($stmt->args[1])
&& isset($stmt->getArgs()[1])
) {
$second_arg = $stmt->args[1]->value;
$second_arg = $stmt->getArgs()[1]->value;
if ($second_arg instanceof PhpParser\Node\Scalar\String_
|| (
@ -1734,11 +1734,11 @@ class AssertionFinder
if ($stmt->name instanceof PhpParser\Node\Name
&& strtolower($stmt->name->parts[0]) === 'class_exists'
) {
if (!isset($stmt->args[1])) {
if (!isset($stmt->getArgs()[1])) {
return 2;
}
$second_arg = $stmt->args[1]->value;
$second_arg = $stmt->getArgs()[1]->value;
if ($second_arg instanceof PhpParser\Node\Expr\ConstFetch
&& strtolower($second_arg->name->parts[0]) === 'true'
@ -1760,11 +1760,11 @@ class AssertionFinder
if ($stmt->name instanceof PhpParser\Node\Name
&& strtolower($stmt->name->parts[0]) === 'trait_exists'
) {
if (!isset($stmt->args[1])) {
if (!isset($stmt->getArgs()[1])) {
return 2;
}
$second_arg = $stmt->args[1]->value;
$second_arg = $stmt->getArgs()[1]->value;
if ($second_arg instanceof PhpParser\Node\Expr\ConstFetch
&& strtolower($second_arg->name->parts[0]) === 'true'
@ -1792,9 +1792,9 @@ class AssertionFinder
{
if ($stmt->name instanceof PhpParser\Node\Name
&& strtolower($stmt->name->parts[0]) === 'in_array'
&& isset($stmt->args[2])
&& isset($stmt->getArgs()[2])
) {
$second_arg = $stmt->args[2]->value;
$second_arg = $stmt->getArgs()[2]->value;
if ($second_arg instanceof PhpParser\Node\Expr\ConstFetch
&& strtolower($second_arg->name->parts[0]) === 'true'
@ -2259,7 +2259,7 @@ class AssertionFinder
/** @var PhpParser\Node\Expr\FuncCall $gettype_expr */
$var_name = ExpressionIdentifier::getArrayVarId(
$gettype_expr->args[0]->value,
$gettype_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -2327,7 +2327,7 @@ class AssertionFinder
/** @var PhpParser\Node\Expr\FuncCall $get_debug_type_expr */
$var_name = ExpressionIdentifier::getArrayVarId(
$get_debug_type_expr->args[0]->value,
$get_debug_type_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -2384,7 +2384,7 @@ class AssertionFinder
if ($getclass_expr instanceof PhpParser\Node\Expr\FuncCall) {
$var_name = ExpressionIdentifier::getArrayVarId(
$getclass_expr->args[0]->value,
$getclass_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -2950,7 +2950,7 @@ class AssertionFinder
/** @var PhpParser\Node\Expr\FuncCall $gettype_expr */
$var_name = ExpressionIdentifier::getArrayVarId(
$gettype_expr->args[0]->value,
$gettype_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -3008,7 +3008,7 @@ class AssertionFinder
/** @var PhpParser\Node\Expr\FuncCall $get_debug_type_expr */
$var_name = ExpressionIdentifier::getArrayVarId(
$get_debug_type_expr->args[0]->value,
$get_debug_type_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -3063,9 +3063,9 @@ class AssertionFinder
throw new \UnexpectedValueException('$getclass_position value');
}
if ($getclass_expr instanceof PhpParser\Node\Expr\FuncCall && isset($getclass_expr->args[0])) {
if ($getclass_expr instanceof PhpParser\Node\Expr\FuncCall && isset($getclass_expr->getArgs()[0])) {
$var_name = ExpressionIdentifier::getArrayVarId(
$getclass_expr->args[0]->value,
$getclass_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -3227,20 +3227,20 @@ class AssertionFinder
): array {
$if_types = [];
if ($expr->args[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& $expr->args[0]->value->name instanceof PhpParser\Node\Identifier
&& strtolower($expr->args[0]->value->name->name) === 'class'
&& $expr->args[0]->value->class instanceof PhpParser\Node\Name
&& count($expr->args[0]->value->class->parts) === 1
&& strtolower($expr->args[0]->value->class->parts[0]) === 'static'
if ($expr->getArgs()[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& $expr->getArgs()[0]->value->name instanceof PhpParser\Node\Identifier
&& strtolower($expr->getArgs()[0]->value->name->name) === 'class'
&& $expr->getArgs()[0]->value->class instanceof PhpParser\Node\Name
&& count($expr->getArgs()[0]->value->class->parts) === 1
&& strtolower($expr->getArgs()[0]->value->class->parts[0]) === 'static'
) {
$first_var_name = '$this';
}
if ($first_var_name) {
$first_arg = $expr->args[0]->value;
$second_arg = $expr->args[1]->value;
$third_arg = $expr->args[2]->value ?? null;
$first_arg = $expr->getArgs()[0]->value;
$second_arg = $expr->getArgs()[1]->value;
$third_arg = $expr->getArgs()[2]->value ?? null;
if ($third_arg instanceof PhpParser\Node\Expr\ConstFetch) {
if (!in_array(strtolower($third_arg->name->parts[0]), ['true', 'false'])) {
@ -3332,9 +3332,9 @@ class AssertionFinder
$if_types = [];
if ($first_var_name
&& ($second_arg_type = $source->node_data->getType($expr->args[1]->value))
&& isset($expr->args[0]->value)
&& !$expr->args[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& ($second_arg_type = $source->node_data->getType($expr->getArgs()[1]->value))
&& isset($expr->getArgs()[0]->value)
&& !$expr->getArgs()[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
) {
foreach ($second_arg_type->getAtomicTypes() as $atomic_type) {
if ($atomic_type instanceof Type\Atomic\TArray
@ -3415,13 +3415,13 @@ class AssertionFinder
$literal_assertions = [];
if (isset($expr->args[0])
&& isset($expr->args[1])
if (isset($expr->getArgs()[0])
&& isset($expr->getArgs()[1])
&& $first_var_type
&& $first_var_name
&& !$expr->args[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& !$expr->getArgs()[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& $source instanceof StatementsAnalyzer
&& ($second_var_type = $source->node_data->getType($expr->args[1]->value))
&& ($second_var_type = $source->node_data->getType($expr->getArgs()[1]->value))
) {
foreach ($second_var_type->getAtomicTypes() as $atomic_type) {
if ($atomic_type instanceof Type\Atomic\TArray
@ -3462,17 +3462,17 @@ class AssertionFinder
if ($literal_assertions && $first_var_name) {
$if_types[$first_var_name] = [$literal_assertions];
} else {
$array_root = isset($expr->args[1]->value)
$array_root = isset($expr->getArgs()[1]->value)
? ExpressionIdentifier::getArrayVarId(
$expr->args[1]->value,
$expr->getArgs()[1]->value,
$this_class_name,
$source
)
: null;
if ($array_root) {
if ($first_var_name === null && isset($expr->args[0])) {
$first_arg = $expr->args[0];
if ($first_var_name === null && isset($expr->getArgs()[0])) {
$first_arg = $expr->getArgs()[0];
if ($first_arg->value instanceof PhpParser\Node\Scalar\String_) {
$first_var_name = '\'' . $first_arg->value->value . '\'';
@ -3481,14 +3481,14 @@ class AssertionFinder
}
}
if ($expr->args[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& $expr->args[0]->value->name instanceof PhpParser\Node\Identifier
&& $expr->args[0]->value->name->name !== 'class'
if ($expr->getArgs()[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& $expr->getArgs()[0]->value->name instanceof PhpParser\Node\Identifier
&& $expr->getArgs()[0]->value->name->name !== 'class'
) {
$const_type = null;
if ($source instanceof StatementsAnalyzer) {
$const_type = $source->node_data->getType($expr->args[0]->value);
$const_type = $source->node_data->getType($expr->getArgs()[0]->value);
}
if ($const_type) {
@ -3502,9 +3502,9 @@ class AssertionFinder
} else {
$first_var_name = null;
}
} elseif ($expr->args[0]->value instanceof PhpParser\Node\Expr\Variable
} elseif ($expr->getArgs()[0]->value instanceof PhpParser\Node\Expr\Variable
&& $source instanceof StatementsAnalyzer
&& ($first_var_type = $source->node_data->getType($expr->args[0]->value))
&& ($first_var_type = $source->node_data->getType($expr->getArgs()[0]->value))
) {
foreach ($first_var_type->getLiteralStrings() as $array_literal_type) {
$if_types[$array_root . "['" . $array_literal_type->value . "']"] = [['array-key-exists']];
@ -3559,7 +3559,7 @@ class AssertionFinder
/** @var PhpParser\Node\Expr\FuncCall $counted_expr */
$var_name = ExpressionIdentifier::getArrayVarId(
$counted_expr->args[0]->value,
$counted_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -3588,7 +3588,7 @@ class AssertionFinder
/** @var PhpParser\Node\Expr\FuncCall $count_expr */
$var_name = ExpressionIdentifier::getArrayVarId(
$count_expr->args[0]->value,
$count_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -3675,7 +3675,7 @@ class AssertionFinder
/** @var PhpParser\Node\Expr\FuncCall $count_expr */
$var_name = ExpressionIdentifier::getArrayVarId(
$count_expr->args[0]->value,
$count_expr->getArgs()[0]->value,
$this_class_name,
$source
);
@ -3700,7 +3700,7 @@ class AssertionFinder
/** @var PhpParser\Node\Expr\FuncCall $count_expr */
$var_name = ExpressionIdentifier::getArrayVarId(
$count_expr->args[0]->value,
$count_expr->getArgs()[0]->value,
$this_class_name,
$source
);

View File

@ -244,14 +244,14 @@ class BinaryOpAnalyzer
&& $stmt->left instanceof PhpParser\Node\Expr\FuncCall
&& $stmt->left->name instanceof PhpParser\Node\Name
&& $stmt->left->name->parts === ['substr']
&& isset($stmt->left->args[1])
&& isset($stmt->left->getArgs()[1])
&& $stmt_right_type
&& $stmt_right_type->hasLiteralString()
) {
$from_type = $statements_analyzer->node_data->getType($stmt->left->args[1]->value);
$from_type = $statements_analyzer->node_data->getType($stmt->left->getArgs()[1]->value);
$length_type = isset($stmt->left->args[2])
? ($statements_analyzer->node_data->getType($stmt->left->args[2]->value) ?: Type::getMixed())
$length_type = isset($stmt->left->getArgs()[2])
? ($statements_analyzer->node_data->getType($stmt->left->getArgs()[2]->value) ?: Type::getMixed())
: null;
$string_length = null;

View File

@ -32,7 +32,7 @@ class ArgumentMapPopulator
$file_content = $codebase->file_provider->getContents($statements_analyzer->getFilePath());
// Find opening paren
$first_argument = $stmt->args[0] ?? null;
$first_argument = $stmt->getArgs()[0] ?? null;
$first_argument_character = $first_argument !== null
? $first_argument->getStartFilePos()
: $stmt->getEndFilePos();
@ -67,7 +67,7 @@ class ArgumentMapPopulator
$ranges = [];
// Add range between opening paren and first argument
$first_argument = $stmt->args[0] ?? null;
$first_argument = $stmt->getArgs()[0] ?? null;
$first_argument_starting_position = $first_argument !== null
? $first_argument->getStartFilePos()
: $stmt->getEndFilePos();
@ -77,9 +77,9 @@ class ArgumentMapPopulator
}
// Add range between arguments
foreach ($stmt->args as $i => $argument) {
foreach ($stmt->getArgs() as $i => $argument) {
$range_start = $argument->getEndFilePos() + 1;
$next_argument = $stmt->args[$i + 1] ?? null;
$next_argument = $stmt->getArgs()[$i + 1] ?? null;
$range_end = $next_argument !== null
? $next_argument->getStartFilePos()
: $stmt->getEndFilePos();

View File

@ -72,15 +72,15 @@ class FunctionCallAnalyzer extends CallAnalyzer
$real_stmt = $stmt;
if ($function_name instanceof PhpParser\Node\Name
&& isset($stmt->args[0])
&& !$stmt->args[0]->unpack
&& isset($stmt->getArgs()[0])
&& !$stmt->getArgs()[0]->unpack
) {
$original_function_id = implode('\\', $function_name->parts);
if ($original_function_id === 'call_user_func') {
$other_args = \array_slice($stmt->args, 1);
$other_args = \array_slice($stmt->getArgs(), 1);
$function_name = $stmt->args[0]->value;
$function_name = $stmt->getArgs()[0]->value;
$stmt = new VirtualFuncCall(
$function_name,
@ -89,12 +89,12 @@ class FunctionCallAnalyzer extends CallAnalyzer
);
}
if ($original_function_id === 'call_user_func_array' && isset($stmt->args[1])) {
$function_name = $stmt->args[0]->value;
if ($original_function_id === 'call_user_func_array' && isset($stmt->getArgs()[1])) {
$function_name = $stmt->getArgs()[0]->value;
$stmt = new VirtualFuncCall(
$function_name,
[new VirtualArg($stmt->args[1]->value, false, true)],
[new VirtualArg($stmt->getArgs()[1]->value, false, true)],
$stmt->getAttributes()
);
}
@ -142,7 +142,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
$function_call_info->function_params,
$function_call_info->function_id,
$function_call_info->allow_named_args,
@ -160,7 +160,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
$function_callable = \Psalm\Internal\Codebase\InternalCallMapHandler::getCallableFromCallMapById(
$codebase,
$function_call_info->function_id,
$stmt->args,
$stmt->getArgs(),
$statements_analyzer->node_data
);
@ -174,7 +174,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
if ($function_call_info->function_params !== null) {
ArgumentsAnalyzer::checkArgumentsMatch(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
$function_call_info->function_id,
$function_call_info->function_params,
$function_call_info->function_storage,
@ -232,13 +232,13 @@ class FunctionCallAnalyzer extends CallAnalyzer
if ($function_name instanceof PhpParser\Node\Name
&& $function_name->parts === ['assert']
&& isset($stmt->args[0])
&& isset($stmt->getArgs()[0])
) {
self::processAssertFunctionEffects(
$statements_analyzer,
$codebase,
$stmt,
$stmt->args[0],
$stmt->getArgs()[0],
$context
);
}
@ -272,7 +272,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
$function_name,
null,
$function_call_info->function_storage->assertions,
$stmt->args,
$stmt->getArgs(),
$inferred_lower_bounds,
$context,
$statements_analyzer
@ -424,7 +424,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
) {
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -451,7 +451,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
$function_call_info->function_params = $codebase->functions->params_provider->getFunctionParams(
$statements_analyzer,
$function_call_info->function_id,
$stmt->args,
$stmt->getArgs(),
null,
$code_location
);
@ -484,7 +484,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
$function_callable = InternalCallMapHandler::getCallableFromCallMapById(
$codebase,
$function_call_info->function_id,
$stmt->args,
$stmt->getArgs(),
$statements_analyzer->node_data
);
@ -789,7 +789,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
$fake_method_call = new VirtualMethodCall(
$function_name,
new VirtualIdentifier('__invoke', $function_name->getAttributes()),
$stmt->args
$stmt->getArgs()
);
$suppressed_issues = $statements_analyzer->getSuppressedIssues();
@ -948,7 +948,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
$codebase,
$statements_analyzer->node_data,
$function_call_info->function_id,
$stmt->args,
$stmt->getArgs(),
$must_use
)
: null;
@ -1031,11 +1031,11 @@ class FunctionCallAnalyzer extends CallAnalyzer
$parameters = $function_call_info->function_params;
// If no arguments were passed
if (0 === \count($stmt->args)) {
if (0 === \count($stmt->getArgs())) {
return false;
}
foreach ($stmt->args as $index => $argument) {
foreach ($stmt->getArgs() as $index => $argument) {
$parameter = null;
if (null !== $argument->name) {
$argument_name = $argument->name->toString();

View File

@ -69,7 +69,7 @@ class FunctionCallReturnTypeFetcher
$template_result->lower_bounds[$template_name] = [
'fn-' . $function_id => [
new TemplateBound(
Type::getInt(false, count($stmt->args))
Type::getInt(false, count($stmt->getArgs()))
)
]
];
@ -187,7 +187,7 @@ class FunctionCallReturnTypeFetcher
$stmt_type = self::getReturnTypeFromCallMapWithArgs(
$statements_analyzer,
$function_id,
$stmt->args,
$stmt->getArgs(),
$callmap_callable,
$context
);
@ -216,7 +216,7 @@ class FunctionCallReturnTypeFetcher
foreach ($function_storage->proxy_calls as $proxy_call) {
$fake_call_arguments = [];
foreach ($proxy_call['params'] as $i) {
$fake_call_arguments[] = $stmt->args[$i];
$fake_call_arguments[] = $stmt->getArgs()[$i];
}
$fake_call_factory = new BuilderFactory();
@ -586,9 +586,9 @@ class FunctionCallReturnTypeFetcher
) {
$removed_taints = $function_storage->removed_taints;
if ($function_id === 'preg_replace' && count($stmt->args) > 2) {
$first_stmt_type = $statements_analyzer->node_data->getType($stmt->args[0]->value);
$second_stmt_type = $statements_analyzer->node_data->getType($stmt->args[1]->value);
if ($function_id === 'preg_replace' && count($stmt->getArgs()) > 2) {
$first_stmt_type = $statements_analyzer->node_data->getType($stmt->getArgs()[0]->value);
$second_stmt_type = $statements_analyzer->node_data->getType($stmt->getArgs()[1]->value);
if ($first_stmt_type
&& $second_stmt_type
@ -627,7 +627,7 @@ class FunctionCallReturnTypeFetcher
$function_storage,
$statements_analyzer->data_flow_graph,
$function_id,
$stmt->args,
$stmt->getArgs(),
$node_location,
$function_call_node,
$removed_taints,

View File

@ -126,7 +126,7 @@ class AtomicMethodCallAnalyzer extends CallAnalyzer
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -170,7 +170,7 @@ class AtomicMethodCallAnalyzer extends CallAnalyzer
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -185,7 +185,7 @@ class AtomicMethodCallAnalyzer extends CallAnalyzer
$method_id = new MethodIdentifier($fq_class_name, $method_name_lc);
$args = $stmt->args;
$args = $stmt->getArgs();
$naive_method_id = $method_id;
@ -627,7 +627,7 @@ class AtomicMethodCallAnalyzer extends CallAnalyzer
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,

View File

@ -428,7 +428,7 @@ class ExistingAtomicMethodCallAnalyzer extends CallAnalyzer
$codebase = $statements_analyzer->getCodebase();
$first_arg_value = $stmt->args[0]->value ?? null;
$first_arg_value = $stmt->getArgs()[0]->value ?? null;
if (!$first_arg_value instanceof PhpParser\Node\Scalar\String_) {
return null;
@ -467,8 +467,8 @@ class ExistingAtomicMethodCallAnalyzer extends CallAnalyzer
// If a `@property` annotation is set, the type of the value passed to the
// magic setter must match the annotation.
$second_arg_type = isset($stmt->args[1])
? $statements_analyzer->node_data->getType($stmt->args[1]->value)
$second_arg_type = isset($stmt->getArgs()[1])
? $statements_analyzer->node_data->getType($stmt->getArgs()[1]->value)
: null;
if (isset($class_storage->pseudo_property_set_types['$' . $prop_name]) && $second_arg_type) {

View File

@ -100,7 +100,7 @@ class MethodCallReturnTypeFetcher
$return_type_candidate,
$template_result,
$method_id,
\count($stmt->args),
\count($stmt->getArgs()),
$codebase
);
} else {
@ -160,7 +160,7 @@ class MethodCallReturnTypeFetcher
$return_type_candidate,
$template_result,
$method_id,
\count($stmt->args),
\count($stmt->getArgs()),
$codebase
);

View File

@ -61,7 +61,7 @@ class MissingMethodCallHandler
CallAnalyzer::checkMethodArgs(
$method_id,
$stmt->args,
$stmt->getArgs(),
null,
$context,
new CodeLocation($statements_analyzer->getSource(), $stmt),
@ -80,7 +80,7 @@ class MissingMethodCallHandler
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
$pseudo_method_storage->params,
(string) $method_id,
true,
@ -89,7 +89,7 @@ class MissingMethodCallHandler
ArgumentsAnalyzer::checkArgumentsMatch(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
$pseudo_method_storage->params,
$pseudo_method_storage,
@ -129,7 +129,7 @@ class MissingMethodCallHandler
} elseif ($all_intersection_return_type === null) {
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -158,7 +158,7 @@ class MissingMethodCallHandler
$arg->getAttributes()
);
},
$stmt->args
$stmt->getArgs()
);
$statements_analyzer->node_data = clone $statements_analyzer->node_data;
@ -217,7 +217,7 @@ class MissingMethodCallHandler
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
$pseudo_method_storage->params,
(string) $method_id,
true,
@ -228,7 +228,7 @@ class MissingMethodCallHandler
if (ArgumentsAnalyzer::checkArgumentsMatch(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
$pseudo_method_storage->params,
$pseudo_method_storage,
@ -274,7 +274,7 @@ class MissingMethodCallHandler
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,

View File

@ -103,7 +103,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
if (!$context->check_classes) {
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -201,7 +201,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
$possible_new_class_types[] = $context->vars_in_scope[$lhs_var_id];
}
}
if (!$stmt->args && $lhs_var_id && $stmt->name instanceof PhpParser\Node\Identifier) {
if (!$stmt->getArgs() && $lhs_var_id && $stmt->name instanceof PhpParser\Node\Identifier) {
if ($codebase->config->memoize_method_calls || $result->can_memoize) {
$method_var_id = $lhs_var_id . '->' . strtolower($stmt->name->name) . '()';
@ -334,7 +334,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
if (IssueBuffer::accepts(
new TooManyArguments(
'Too many arguments for method ' . $error_method_id . ' - saw ' . count($stmt->args),
'Too many arguments for method ' . $error_method_id . ' - saw ' . count($stmt->getArgs()),
new CodeLocation($source, $stmt->name),
(string) $error_method_id
),
@ -349,7 +349,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
if (IssueBuffer::accepts(
new TooFewArguments(
'Too few arguments for method ' . $error_method_id . ' saw ' . count($stmt->args),
'Too few arguments for method ' . $error_method_id . ' saw ' . count($stmt->getArgs()),
new CodeLocation($source, $stmt->name),
(string) $error_method_id
),
@ -390,7 +390,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
if (!$result->existent_method_ids) {
return self::checkMethodArgs(
null,
$stmt->args,
$stmt->getArgs(),
null,
$context,
new CodeLocation($statements_analyzer->getSource(), $stmt),

View File

@ -60,10 +60,10 @@ class NamedFunctionCallHandler
return;
}
$first_arg = $stmt->args[0] ?? null;
$first_arg = $stmt->getArgs()[0] ?? null;
if ($function_id === 'method_exists') {
$second_arg = $stmt->args[1] ?? null;
$second_arg = $stmt->getArgs()[1] ?? null;
if ($first_arg
&& $first_arg->value instanceof PhpParser\Node\Expr\Variable
@ -183,7 +183,7 @@ class NamedFunctionCallHandler
$all_args_string_literals = true;
$new_items = [];
foreach ($stmt->args as $arg) {
foreach ($stmt->getArgs() as $arg) {
$arg_type = $statements_analyzer->node_data->getType($arg->value);
if (!$arg_type || !$arg_type->isSingleStringLiteral()) {
@ -275,8 +275,8 @@ class NamedFunctionCallHandler
$statements_analyzer->getAliases()
);
if ($fq_const_name !== null && isset($stmt->args[1])) {
$second_arg = $stmt->args[1];
if ($fq_const_name !== null && isset($stmt->getArgs()[1])) {
$second_arg = $stmt->getArgs()[1];
$was_in_call = $context->inside_call;
$context->inside_call = true;
ExpressionAnalyzer::analyze($statements_analyzer, $second_arg->value, $context);
@ -436,7 +436,7 @@ class NamedFunctionCallHandler
string $function_id,
Context $context
) : void {
$first_arg = $stmt->args[0] ?? null;
$first_arg = $stmt->getArgs()[0] ?? null;
if ($first_arg) {
$var = $first_arg->value;

View File

@ -151,7 +151,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
if ($context->isPhantomClass($fq_class_name)) {
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -171,7 +171,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
) === false) {
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -224,7 +224,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
} else {
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -360,7 +360,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
if (self::checkMethodArgs(
$method_id,
$stmt->args,
$stmt->getArgs(),
$template_result,
$context,
new CodeLocation($statements_analyzer->getSource(), $stmt),
@ -430,7 +430,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
$stmt->class,
null,
$method_storage->assertions,
$stmt->args,
$stmt->getArgs(),
$generic_params,
$context,
$statements_analyzer
@ -518,7 +518,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
new Type\Union([$result_atomic_type])
);
}
} elseif ($stmt->args) {
} elseif ($stmt->getArgs()) {
if (IssueBuffer::accepts(
new TooManyArguments(
'Class ' . $fq_class_name . ' has no __construct, but arguments were passed',
@ -617,7 +617,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
if (!$stmt_class_type) {
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -634,7 +634,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
} else {
if (self::checkMethodArgs(
null,
$stmt->args,
$stmt->getArgs(),
null,
$context,
new CodeLocation($statements_analyzer->getSource(), $stmt),
@ -846,7 +846,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,

View File

@ -186,7 +186,7 @@ class StaticCallAnalyzer extends CallAnalyzer
if (!$lhs_type) {
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -218,7 +218,7 @@ class StaticCallAnalyzer extends CallAnalyzer
if (!$has_existing_method) {
return self::checkMethodArgs(
$method_id,
$stmt->args,
$stmt->getArgs(),
null,
$context,
new CodeLocation($statements_analyzer->getSource(), $stmt),
@ -363,7 +363,7 @@ class StaticCallAnalyzer extends CallAnalyzer
$method_storage,
$statements_analyzer->data_flow_graph,
(string) $method_id,
$stmt->args,
$stmt->getArgs(),
$node_location,
$method_source,
\array_merge($method_storage->removed_taints, $removed_taints),

View File

@ -205,7 +205,7 @@ class AtomicStaticCallAnalyzer
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -263,7 +263,7 @@ class AtomicStaticCallAnalyzer
);
}
$args = $stmt->args;
$args = $stmt->getArgs();
if ($intersection_types
&& !$codebase->methods->methodExists($method_id)
@ -411,7 +411,7 @@ class AtomicStaticCallAnalyzer
$stmt->class->getAttributes()
),
$stmt_name,
$stmt->args,
$stmt->getArgs(),
$stmt->getAttributes()
);
@ -481,7 +481,7 @@ class AtomicStaticCallAnalyzer
if ($return_type_candidate) {
CallAnalyzer::checkMethodArgs(
$method_id,
$stmt->args,
$stmt->getArgs(),
null,
$context,
new CodeLocation($statements_analyzer->getSource(), $stmt),
@ -585,7 +585,7 @@ class AtomicStaticCallAnalyzer
if (!$context->check_methods) {
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -609,7 +609,7 @@ class AtomicStaticCallAnalyzer
if (!$does_method_exist) {
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,
$stmt->getArgs(),
null,
null,
true,
@ -704,7 +704,7 @@ class AtomicStaticCallAnalyzer
$stmt->class->getAttributes()
),
$stmt_name,
$stmt->args,
$stmt->getArgs(),
$stmt->getAttributes()
);

View File

@ -307,7 +307,7 @@ class ExistingAtomicStaticCallAnalyzer
$stmt_name,
null,
$method_storage->assertions,
$stmt->args,
$stmt->getArgs(),
$generic_params,
$context,
$statements_analyzer
@ -487,7 +487,7 @@ class ExistingAtomicStaticCallAnalyzer
$template_result->lower_bounds[$template_type->param_name] = [
'fn-' . strtolower((string)$method_id) => [
new TemplateBound(
Type::getInt(false, count($stmt->args))
Type::getInt(false, count($stmt->getArgs()))
)
]
];

View File

@ -197,7 +197,7 @@ class ExpressionIdentifier
if ($stmt instanceof PhpParser\Node\Expr\MethodCall
&& $stmt->name instanceof PhpParser\Node\Identifier
&& !$stmt->args
&& !$stmt->getArgs()
) {
$config = \Psalm\Config::getInstance();

View File

@ -324,19 +324,19 @@ class IncludeAnalyzer
$stmt->name instanceof PhpParser\Node\Name &&
$stmt->name->parts === ['dirname']
) {
if ($stmt->args) {
if ($stmt->getArgs()) {
$dir_level = 1;
if (isset($stmt->args[1])) {
if ($stmt->args[1]->value instanceof PhpParser\Node\Scalar\LNumber) {
$dir_level = $stmt->args[1]->value->value;
if (isset($stmt->getArgs()[1])) {
if ($stmt->getArgs()[1]->value instanceof PhpParser\Node\Scalar\LNumber) {
$dir_level = $stmt->getArgs()[1]->value->value;
} else {
return null;
}
}
$evaled_path = self::getPathTo(
$stmt->args[0]->value,
$stmt->getArgs()[0]->value,
$type_provider,
$statements_analyzer,
$file_name,

View File

@ -64,9 +64,9 @@ class MatchAnalyzer
&& ($stmt->cond->name->parts === ['get_class']
|| $stmt->cond->name->parts === ['gettype']
|| $stmt->cond->name->parts === ['get_debug_type'])
&& $stmt->cond->args
&& $stmt->cond->getArgs()
) {
$first_arg = $stmt->cond->args[0];
$first_arg = $stmt->cond->getArgs()[0];
if (!$first_arg->value instanceof PhpParser\Node\Expr\Variable) {
$switch_var_id = '$__tmp_switch__' . (int) $first_arg->value->getAttribute('startFilePos');

View File

@ -298,10 +298,10 @@ class StatementsAnalyzer extends SourceAnalyzer
&& $stmt->expr instanceof PhpParser\Node\Expr\FuncCall
&& $stmt->expr->name instanceof PhpParser\Node\Name
&& $stmt->expr->name->parts === ['define']
&& isset($stmt->expr->args[1])
&& isset($stmt->expr->getArgs()[1])
) {
$const_name = ConstFetchAnalyzer::getConstName(
$stmt->expr->args[0]->value,
$stmt->expr->getArgs()[0]->value,
$statements_analyzer->node_data,
$codebase,
$statements_analyzer->getAliases()
@ -314,7 +314,7 @@ class StatementsAnalyzer extends SourceAnalyzer
Statements\Expression\SimpleTypeInferer::infer(
$codebase,
$statements_analyzer->node_data,
$stmt->expr->args[1]->value,
$stmt->expr->getArgs()[1]->value,
$statements_analyzer->getAliases(),
$statements_analyzer
) ?: Type::getMixed(),

View File

@ -76,7 +76,7 @@ class AssignmentMapVisitor extends PhpParser\NodeVisitorAbstract
|| $node instanceof PhpParser\Node\Expr\MethodCall
|| $node instanceof PhpParser\Node\Expr\StaticCall
) {
foreach ($node->args as $arg) {
foreach ($node->getArgs() as $arg) {
$arg_var_id = ExpressionIdentifier::getRootVarId($arg->value, $this->this_class_name);
if ($arg_var_id) {

View File

@ -317,11 +317,11 @@ class ExpressionResolver
}
if ($function->name->parts === ['function_exists']
&& isset($function->args[0])
&& $function->args[0]->value instanceof PhpParser\Node\Scalar\String_
&& function_exists($function->args[0]->value->value)
&& isset($function->getArgs()[0])
&& $function->getArgs()[0]->value instanceof PhpParser\Node\Scalar\String_
&& function_exists($function->getArgs()[0]->value->value)
) {
$reflection_function = new \ReflectionFunction($function->args[0]->value->value);
$reflection_function = new \ReflectionFunction($function->getArgs()[0]->value->value);
if ($reflection_function->isInternal()) {
return true;
@ -331,18 +331,18 @@ class ExpressionResolver
}
if ($function->name->parts === ['class_exists']
&& isset($function->args[0])
&& isset($function->getArgs()[0])
) {
$string_value = null;
if ($function->args[0]->value instanceof PhpParser\Node\Scalar\String_) {
$string_value = $function->args[0]->value->value;
} elseif ($function->args[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& $function->args[0]->value->class instanceof PhpParser\Node\Name
&& $function->args[0]->value->name instanceof PhpParser\Node\Identifier
&& strtolower($function->args[0]->value->name->name) === 'class'
if ($function->getArgs()[0]->value instanceof PhpParser\Node\Scalar\String_) {
$string_value = $function->getArgs()[0]->value->value;
} elseif ($function->getArgs()[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& $function->getArgs()[0]->value->class instanceof PhpParser\Node\Name
&& $function->getArgs()[0]->value->name instanceof PhpParser\Node\Identifier
&& strtolower($function->getArgs()[0]->value->name->name) === 'class'
) {
$string_value = (string) $function->args[0]->value->class->getAttribute('resolvedName');
$string_value = (string) $function->getArgs()[0]->value->class->getAttribute('resolvedName');
}
if ($string_value && class_exists($string_value)) {
@ -361,18 +361,18 @@ class ExpressionResolver
}
if ($function->name->parts === ['interface_exists']
&& isset($function->args[0])
&& isset($function->getArgs()[0])
) {
$string_value = null;
if ($function->args[0]->value instanceof PhpParser\Node\Scalar\String_) {
$string_value = $function->args[0]->value->value;
} elseif ($function->args[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& $function->args[0]->value->class instanceof PhpParser\Node\Name
&& $function->args[0]->value->name instanceof PhpParser\Node\Identifier
&& strtolower($function->args[0]->value->name->name) === 'class'
if ($function->getArgs()[0]->value instanceof PhpParser\Node\Scalar\String_) {
$string_value = $function->getArgs()[0]->value->value;
} elseif ($function->getArgs()[0]->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& $function->getArgs()[0]->value->class instanceof PhpParser\Node\Name
&& $function->getArgs()[0]->value->name instanceof PhpParser\Node\Identifier
&& strtolower($function->getArgs()[0]->value->name->name) === 'class'
) {
$string_value = (string) $function->args[0]->value->class->getAttribute('resolvedName');
$string_value = (string) $function->getArgs()[0]->value->class->getAttribute('resolvedName');
}
if ($string_value && interface_exists($string_value)) {

View File

@ -123,8 +123,8 @@ class ExpressionScanner
}
if ($function_id === 'define') {
$first_arg_value = isset($node->args[0]) ? $node->args[0]->value : null;
$second_arg_value = isset($node->args[1]) ? $node->args[1]->value : null;
$first_arg_value = isset($node->getArgs()[0]) ? $node->getArgs()[0]->value : null;
$second_arg_value = isset($node->getArgs()[1]) ? $node->getArgs()[1]->value : null;
if ($first_arg_value && $second_arg_value) {
$type_provider = new \Psalm\Internal\Provider\NodeDataProvider();
$const_name = ConstFetchAnalyzer::getConstName(
@ -162,10 +162,10 @@ class ExpressionScanner
$mapping_function_ids = [];
if (($function_id === 'array_map' && isset($node->args[0]))
|| ($function_id === 'array_filter' && isset($node->args[1]))
if (($function_id === 'array_map' && isset($node->getArgs()[0]))
|| ($function_id === 'array_filter' && isset($node->getArgs()[1]))
) {
$node_arg_value = $function_id === 'array_map' ? $node->args[0]->value : $node->args[1]->value;
$node_arg_value = $function_id === 'array_map' ? $node->getArgs()[0]->value : $node->getArgs()[1]->value;
if ($node_arg_value instanceof PhpParser\Node\Scalar\String_
|| $node_arg_value instanceof PhpParser\Node\Expr\Array_
@ -202,7 +202,7 @@ class ExpressionScanner
}
if ($function_id === 'is_a' || $function_id === 'is_subclass_of') {
$second_arg = $node->args[1]->value ?? null;
$second_arg = $node->getArgs()[1]->value ?? null;
if ($second_arg instanceof PhpParser\Node\Scalar\String_) {
$codebase->scanner->queueClassLikeForScanning(
@ -212,8 +212,8 @@ class ExpressionScanner
}
if ($function_id === 'class_alias' && !$skip_if_descendants) {
$first_arg = $node->args[0]->value ?? null;
$second_arg = $node->args[1]->value ?? null;
$first_arg = $node->getArgs()[0]->value ?? null;
$second_arg = $node->getArgs()[1]->value ?? null;
if ($first_arg instanceof PhpParser\Node\Scalar\String_) {
$first_arg_value = $first_arg->value;

View File

@ -506,7 +506,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements FileSour
&& $meta_stmt->expr->name instanceof PhpParser\Node\Name
&& $meta_stmt->expr->name->parts === ['override']
) {
PhpStormMetaScanner::handleOverride($meta_stmt->expr->args, $this->codebase);
PhpStormMetaScanner::handleOverride($meta_stmt->expr->getArgs(), $this->codebase);
}
}
}

View File

@ -18,12 +18,12 @@ class HtmlFunctionTainter implements AddTaintsInterface, RemoveTaintsInterface
{
$item = $event->getExpr();
$statements_analyzer = $event->getStatementsSource();
if (!$statements_analyzer instanceof StatementsAnalyzer
|| !$item instanceof PhpParser\Node\Expr\FuncCall
|| !$item->name instanceof PhpParser\Node\Name
|| \count($item->name->parts) !== 1
|| \count($item->args) === 0
|| \count($item->getArgs()) === 0
) {
return [];
}
@ -33,7 +33,7 @@ class HtmlFunctionTainter implements AddTaintsInterface, RemoveTaintsInterface
if ($function_id === 'html_entity_decode'
|| $function_id === 'htmlspecialchars_decode'
) {
$second_arg = $item->args[1]->value ?? null;
$second_arg = $item->getArgs()[1]->value ?? null;
if ($second_arg === null) {
return ['html'];
@ -46,7 +46,7 @@ class HtmlFunctionTainter implements AddTaintsInterface, RemoveTaintsInterface
}
$second_arg_value = $second_arg_value->getSingleIntLiteral()->value;
if (($second_arg_value & \ENT_QUOTES) === \ENT_QUOTES) {
return ['html', 'has_quotes'];
}
@ -66,12 +66,12 @@ class HtmlFunctionTainter implements AddTaintsInterface, RemoveTaintsInterface
{
$item = $event->getExpr();
$statements_analyzer = $event->getStatementsSource();
if (!$statements_analyzer instanceof StatementsAnalyzer
|| !$item instanceof PhpParser\Node\Expr\FuncCall
|| !$item->name instanceof PhpParser\Node\Name
|| \count($item->name->parts) !== 1
|| \count($item->args) === 0
|| \count($item->getArgs()) === 0
) {
return [];
}
@ -81,7 +81,7 @@ class HtmlFunctionTainter implements AddTaintsInterface, RemoveTaintsInterface
if ($function_id === 'htmlentities'
|| $function_id === 'htmlspecialchars'
) {
$second_arg = $item->args[1]->value ?? null;
$second_arg = $item->getArgs()[1]->value ?? null;
if ($second_arg === null) {
return ['html'];
@ -94,14 +94,14 @@ class HtmlFunctionTainter implements AddTaintsInterface, RemoveTaintsInterface
}
$second_arg_value = $second_arg_value->getSingleIntLiteral()->value;
if (($second_arg_value & \ENT_QUOTES) === \ENT_QUOTES) {
return ['html', 'has_quotes'];
}
return ['html'];
}
return [];
}
}

View File

@ -139,7 +139,7 @@ class FunctionReturnTypeProvider
$return_type = $function_handler(
$statements_source,
$function_id,
$stmt->args,
$stmt->getArgs(),
$context,
$code_location
);

View File

@ -125,7 +125,7 @@ class MethodReturnTypeProvider
$statements_source,
$fq_classlike_name,
strtolower($method_name),
$stmt->args,
$stmt->getArgs(),
$context,
$code_location,
$template_type_parameters,

View File

@ -39,10 +39,10 @@ class PhpStormMetaScanner
$map = [];
if ($args[1]->value->name->parts === ['map']
&& $args[1]->value->args
&& $args[1]->value->args[0]->value instanceof PhpParser\Node\Expr\Array_
&& $args[1]->value->getArgs()
&& $args[1]->value->getArgs()[0]->value instanceof PhpParser\Node\Expr\Array_
) {
foreach ($args[1]->value->args[0]->value->items as $array_item) {
foreach ($args[1]->value->getArgs()[0]->value->items as $array_item) {
if ($array_item
&& $array_item->key instanceof PhpParser\Node\Scalar\String_
) {
@ -64,33 +64,33 @@ class PhpStormMetaScanner
$type_offset = null;
if ($args[1]->value->name->parts === ['type']
&& $args[1]->value->args
&& $args[1]->value->args[0]->value instanceof PhpParser\Node\Scalar\LNumber
&& $args[1]->value->getArgs()
&& $args[1]->value->getArgs()[0]->value instanceof PhpParser\Node\Scalar\LNumber
) {
$type_offset = $args[1]->value->args[0]->value->value;
$type_offset = $args[1]->value->getArgs()[0]->value->value;
}
$element_type_offset = null;
if ($args[1]->value->name->parts === ['elementType']
&& $args[1]->value->args
&& $args[1]->value->args[0]->value instanceof PhpParser\Node\Scalar\LNumber
&& $args[1]->value->getArgs()
&& $args[1]->value->getArgs()[0]->value instanceof PhpParser\Node\Scalar\LNumber
) {
$element_type_offset = $args[1]->value->args[0]->value->value;
$element_type_offset = $args[1]->value->getArgs()[0]->value->value;
}
if ($identifier instanceof PhpParser\Node\Expr\StaticCall
&& $identifier->class instanceof PhpParser\Node\Name\FullyQualified
&& $identifier->name instanceof PhpParser\Node\Identifier
&& $identifier->args
&& $identifier->args[0]->value instanceof PhpParser\Node\Scalar\LNumber
&& $identifier->getArgs()
&& $identifier->getArgs()[0]->value instanceof PhpParser\Node\Scalar\LNumber
) {
$meta_fq_classlike_name = implode('\\', $identifier->class->parts);
$meta_method_name = strtolower($identifier->name->name);
if ($map) {
$offset = $identifier->args[0]->value->value;
$offset = $identifier->getArgs()[0]->value->value;
$codebase->methods->return_type_provider->registerClosure(
$meta_fq_classlike_name,
@ -241,13 +241,13 @@ class PhpStormMetaScanner
if ($identifier instanceof PhpParser\Node\Expr\FuncCall
&& $identifier->name instanceof PhpParser\Node\Name\FullyQualified
&& $identifier->args
&& $identifier->args[0]->value instanceof PhpParser\Node\Scalar\LNumber
&& $identifier->getArgs()
&& $identifier->getArgs()[0]->value instanceof PhpParser\Node\Scalar\LNumber
) {
$function_id = strtolower(implode('\\', $identifier->name->parts));
if ($map) {
$offset = $identifier->args[0]->value->value;
$offset = $identifier->getArgs()[0]->value->value;
$codebase->functions->return_type_provider->registerClosure(
$function_id,

View File

@ -70,7 +70,7 @@ class FunctionReturnTypeProviderEvent
*/
public function getCallArgs(): array
{
return $this->stmt->args;
return $this->stmt->getArgs();
}
public function getContext(): Context

View File

@ -103,7 +103,7 @@ class MethodReturnTypeProviderEvent
*/
public function getCallArgs(): array
{
return $this->stmt->args;
return $this->stmt->getArgs();
}
public function getContext(): Context

22
stubs/phpparser.phpstub Normal file
View File

@ -0,0 +1,22 @@
<?php declare(strict_types=1);
namespace PhpParser\Node\Expr;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\VariadicPlaceholder;
abstract class CallLike extends Expr {
/**
* @return list<Arg|VariadicPlaceholder>
*/
abstract public function getRawArgs(): array;
public function isFirstClassCallable(): bool {}
/**
* @psalm-pure
* @return list<Arg>
*/
public function getArgs(): array{}
}