Skip to content

Commit

Permalink
Allow enabling mixed issues reporting for error levels > 2.
Browse files Browse the repository at this point in the history
Refs #9619.
  • Loading branch information
ADmad committed Apr 8, 2023
1 parent 82b3a7c commit a584314
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,8 @@ public function shortenFileName(string $to): string

public function reportIssueInFile(string $issue_type, string $file_path): bool
{
if (($this->show_mixed_issues === false || $this->level > 2)
if ((($this->level < 3 && $this->show_mixed_issues === false)
|| ($this->level > 2 && $this->show_mixed_issues !== true))
&& in_array($issue_type, self::MIXED_ISSUES, true)
) {
return false;
Expand Down
71 changes: 71 additions & 0 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,77 @@ public function testIssueHandler(): void
$this->assertFalse($config->reportIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php')));
}

public function testReportMixedIssues(): void
{
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
Config::loadFromXML(
dirname(__DIR__, 2),
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
<directory name="tests" />
</projectFiles>
</psalm>',
),
);
$config = $this->project_analyzer->getConfig();

$this->assertNull($config->show_mixed_issues);
$this->assertTrue($config->reportIssueInFile('MixedArgument', realpath(__FILE__)));

$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
Config::loadFromXML(
dirname(__DIR__, 2),
'<?xml version="1.0"?>
<psalm reportMixedIssues="false">
<projectFiles>
<directory name="src" />
<directory name="tests" />
</projectFiles>
</psalm>',
),
);
$config = $this->project_analyzer->getConfig();

$this->assertFalse($config->show_mixed_issues);
$this->assertFalse($config->reportIssueInFile('MixedArgument', realpath(__FILE__)));

$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
Config::loadFromXML(
dirname(__DIR__, 2),
'<?xml version="1.0"?>
<psalm errorLevel="5">
<projectFiles>
<directory name="src" />
<directory name="tests" />
</projectFiles>
</psalm>',
),
);
$config = $this->project_analyzer->getConfig();

$this->assertNull($config->show_mixed_issues);
$this->assertFalse($config->reportIssueInFile('MixedArgument', realpath(__FILE__)));

$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
Config::loadFromXML(
dirname(__DIR__, 2),
'<?xml version="1.0"?>
<psalm errorLevel="5" reportMixedIssues="true">
<projectFiles>
<directory name="src" />
<directory name="tests" />
</projectFiles>
</psalm>',
),
);
$config = $this->project_analyzer->getConfig();

$this->assertTrue($config->show_mixed_issues);
$this->assertTrue($config->reportIssueInFile('MixedArgument', realpath(__FILE__)));
}

public function testGlobalUndefinedFunctionSuppression(): void
{
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
Expand Down

0 comments on commit a584314

Please sign in to comment.