mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Fix #518 - improve dead code detection to cover variable method calls
This commit is contained in:
parent
b041797cd0
commit
a0e88cb16f
@ -48,6 +48,12 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_string($stmt->name)) {
|
||||||
|
if (ExpressionChecker::analyze($statements_checker, $stmt->name, $context) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$method_id = null;
|
$method_id = null;
|
||||||
|
|
||||||
if ($stmt->var instanceof PhpParser\Node\Expr\Variable) {
|
if ($stmt->var instanceof PhpParser\Node\Expr\Variable) {
|
||||||
|
@ -623,6 +623,23 @@ class UnusedCodeTest extends TestCase
|
|||||||
|
|
||||||
new A([1, 2, 3]);',
|
new A([1, 2, 3]);',
|
||||||
],
|
],
|
||||||
|
'usedMethodCallVariable' => [
|
||||||
|
'<?php
|
||||||
|
function reindex(array $arr, string $methodName): array {
|
||||||
|
$ret = [];
|
||||||
|
|
||||||
|
foreach ($arr as $element) {
|
||||||
|
$ret[$element->$methodName()] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}',
|
||||||
|
'error_levels' => [
|
||||||
|
'MixedAssignment',
|
||||||
|
'MixedMethodCall',
|
||||||
|
'MixedArrayOffset',
|
||||||
|
],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user