mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #6899 from pilif/fix-6887
don't stop processing for class usage after raising an issue
This commit is contained in:
commit
2d0758ab10
@ -357,7 +357,7 @@ class StatementsAnalyzer extends SourceAnalyzer
|
||||
),
|
||||
$statements_analyzer->source->getSuppressedIssues()
|
||||
)) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,13 @@ use Psalm\Config;
|
||||
use Psalm\Context;
|
||||
use Psalm\Internal\Provider\FakeFileProvider;
|
||||
use Psalm\Internal\RuntimeCaches;
|
||||
use Psalm\IssueBuffer;
|
||||
use Psalm\Tests\Internal\Provider;
|
||||
|
||||
use function getcwd;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
class UnusedCodeTest extends TestCase
|
||||
{
|
||||
/** @var \Psalm\Internal\Analyzer\ProjectAnalyzer */
|
||||
@ -99,6 +104,70 @@ class UnusedCodeTest extends TestCase
|
||||
\Psalm\IssueBuffer::processUnusedSuppressions($this->project_analyzer->getCodebase()->file_provider);
|
||||
}
|
||||
|
||||
public function testSeesClassesUsedAfterUnevaluatedCodeIssue(): void
|
||||
{
|
||||
$this->project_analyzer->getConfig()->throw_exception = false;
|
||||
$file_path = getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php';
|
||||
|
||||
$this->addFile(
|
||||
$file_path,
|
||||
'<?php
|
||||
if (rand(0, 1)) {
|
||||
throw new Exception("foo");
|
||||
echo "bar";
|
||||
} else {
|
||||
$f = new Foo();
|
||||
$f->bar();
|
||||
}
|
||||
|
||||
class Foo {
|
||||
function bar(): void{
|
||||
echo "foo";
|
||||
}
|
||||
}
|
||||
'
|
||||
);
|
||||
$this->analyzeFile($file_path, new Context(), false);
|
||||
$this->project_analyzer->consolidateAnalyzedData();
|
||||
|
||||
$this->assertSame(1, IssueBuffer::getErrorCount());
|
||||
$issue = IssueBuffer::getIssuesDataForFile($file_path)[0];
|
||||
$this->assertSame('UnevaluatedCode', $issue->type);
|
||||
$this->assertSame(4, $issue->line_from);
|
||||
}
|
||||
|
||||
public function testSeesUnusedClassReferencedByUnevaluatedCode(): void
|
||||
{
|
||||
$this->project_analyzer->getConfig()->throw_exception = false;
|
||||
$file_path = getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php';
|
||||
|
||||
$this->addFile(
|
||||
$file_path,
|
||||
'<?php
|
||||
if (rand(0, 1)) {
|
||||
throw new Exception("foo");
|
||||
$f = new Foo();
|
||||
$f->bar();
|
||||
} else {
|
||||
echo "bar";
|
||||
}
|
||||
|
||||
class Foo {
|
||||
function bar(): void{
|
||||
echo "foo";
|
||||
}
|
||||
}
|
||||
'
|
||||
);
|
||||
$this->analyzeFile($file_path, new Context(), false);
|
||||
$this->project_analyzer->consolidateAnalyzedData();
|
||||
|
||||
$this->assertSame(3, IssueBuffer::getErrorCount());
|
||||
$issue = IssueBuffer::getIssuesDataForFile($file_path)[2];
|
||||
$this->assertSame('UnusedClass', $issue->type);
|
||||
$this->assertSame(10, $issue->line_from);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{string}>
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user