mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Report RawObjectIteration
when array_walk
is used on objects
This commit is contained in:
parent
6cff8b627f
commit
b370ce92aa
@ -403,6 +403,32 @@ class NamedFunctionCallHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($first_arg && $function_id === 'array_walk') {
|
||||
$first_arg_type = $statements_analyzer->node_data->getType($first_arg->value);
|
||||
|
||||
if ($first_arg_type && $first_arg_type->hasObjectType()) {
|
||||
if ($first_arg_type->isSingle()) {
|
||||
if (IssueBuffer::accepts(
|
||||
new \Psalm\Issue\RawObjectIteration(
|
||||
'Possibly undesired iteration over object properties',
|
||||
new CodeLocation($statements_analyzer, $function_name)
|
||||
)
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
} else {
|
||||
if (IssueBuffer::accepts(
|
||||
new \Psalm\Issue\PossibleRawObjectIteration(
|
||||
'Possibly undesired iteration over object properties',
|
||||
new CodeLocation($statements_analyzer, $function_name)
|
||||
)
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleDependentTypeFunction(
|
||||
|
@ -2170,6 +2170,13 @@ class ArrayFunctionCallTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'LessSpecificReturnStatement - src' . DIRECTORY_SEPARATOR . 'somefile.php:9:32 - The type \'array{A: int|string}<string, string>\' is more general',
|
||||
],
|
||||
'arrayWalkOverObject' => [
|
||||
'<?php
|
||||
$o = new stdClass();
|
||||
array_walk($o, "var_dump");
|
||||
',
|
||||
'error_message' => 'RawObjectIteration',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user