mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Make dead code check emit an issue
This commit is contained in:
parent
6b2bb7d917
commit
f4857eb0dd
@ -13,6 +13,7 @@ use Psalm\Context;
|
||||
use Psalm\EffectsAnalyser;
|
||||
use Psalm\Exception\DocblockParseException;
|
||||
use Psalm\FunctionLikeParameter;
|
||||
use Psalm\Issue\DeadCode;
|
||||
use Psalm\Issue\DuplicateParam;
|
||||
use Psalm\Issue\InvalidDocblock;
|
||||
use Psalm\Issue\InvalidParamDefault;
|
||||
@ -353,8 +354,18 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
strpos($var_name, '[') === false &&
|
||||
$var_name !== '$_'
|
||||
) {
|
||||
if (!isset($context->referenced_vars[$var_name])) {
|
||||
echo 'Variable ' . $var_name . ' is not referenced in ' . $cased_method_id . PHP_EOL;
|
||||
$original_location = $statements_checker->getFirstAppearance($var_name);
|
||||
|
||||
if (!isset($context->referenced_vars[$var_name]) && $original_location) {
|
||||
if (IssueBuffer::accepts(
|
||||
new DeadCode(
|
||||
'Variable ' . $var_name . ' is never used',
|
||||
$original_location
|
||||
),
|
||||
$this->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ class ForeachChecker
|
||||
if (!$statements_checker->hasVariable($key_var_id)) {
|
||||
$statements_checker->registerVariable(
|
||||
$key_var_id,
|
||||
new CodeLocation($statements_checker, $stmt)
|
||||
new CodeLocation($statements_checker, $stmt->keyVar)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ class TryChecker
|
||||
if (!$statements_checker->hasVariable($catch_var_id)) {
|
||||
$statements_checker->registerVariable(
|
||||
$catch_var_id,
|
||||
new CodeLocation($statements_checker, $catch)
|
||||
new CodeLocation($statements_checker, $catch, true)
|
||||
);
|
||||
}
|
||||
|
||||
|
6
src/Psalm/Issue/DeadCode.php
Normal file
6
src/Psalm/Issue/DeadCode.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
class DeadCode extends CodeError
|
||||
{
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user