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

Fix #518 - improve dead code detection to cover variable method calls

This commit is contained in:
Matthew Brown 2018-02-17 17:23:57 -05:00
parent b041797cd0
commit a0e88cb16f
2 changed files with 23 additions and 0 deletions

View File

@ -48,6 +48,12 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
return false;
}
if (!is_string($stmt->name)) {
if (ExpressionChecker::analyze($statements_checker, $stmt->name, $context) === false) {
return false;
}
}
$method_id = null;
if ($stmt->var instanceof PhpParser\Node\Expr\Variable) {

View File

@ -623,6 +623,23 @@ class UnusedCodeTest extends TestCase
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',
],
],
];
}