1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Complain about unevaluated code in more concrete fashion

This commit is contained in:
Matthew Brown 2017-02-12 16:49:32 -05:00
parent b80628b1c4
commit e0e92785f8
3 changed files with 19 additions and 2 deletions

View File

@ -166,6 +166,7 @@
<xs:element name="UnimplementedInterfaceMethod" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UnrecognizedExpression" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UnrecognizedStatement" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UnevaluatedCode" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UnusedVariable" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UnusedClass" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UnusedMethod" type="IssueHandlerType" minOccurs="0" />

View File

@ -18,6 +18,7 @@ use Psalm\Exception\FileIncludeException;
use Psalm\Issue\ContinueOutsideLoop;
use Psalm\Issue\InvalidGlobal;
use Psalm\Issue\InvalidNamespace;
use Psalm\Issue\UnevaluatedCode;
use Psalm\Issue\UnrecognizedStatement;
use Psalm\IssueBuffer;
use Psalm\StatementsSource;
@ -98,8 +99,17 @@ class StatementsChecker extends SourceChecker implements StatementsSource
if ($has_returned && !($stmt instanceof PhpParser\Node\Stmt\Nop) &&
!($stmt instanceof PhpParser\Node\Stmt\InlineHTML)
) {
echo('Warning: Expressions after return/throw/continue in ' .
$this->getCheckedFileName() . ' on line ' . $stmt->getLine() . PHP_EOL);
if ($context->count_references) {
if (IssueBuffer::accepts(
new UnevaluatedCode(
'Expressions after return/throw/continue',
new CodeLocation($this->source, $stmt)
),
$this->source->getSuppressedIssues()
)) {
return false;
}
}
break;
}

View File

@ -0,0 +1,6 @@
<?php
namespace Psalm\Issue;
class UnevaluatedCode extends CodeError
{
}