Skip to content

Commit

Permalink
Merge pull request #7657 from weirdan/fix-7610
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Feb 12, 2022
2 parents a3852b8 + dc776d3 commit 293937f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Psalm/Config.php
Expand Up @@ -1790,11 +1790,22 @@ public function getReportingLevelForMethod(string $issue_type, string $method_id

public function getReportingLevelForFunction(string $issue_type, string $function_id): ?string
{
$level = null;
if (isset($this->issue_handlers[$issue_type])) {
return $this->issue_handlers[$issue_type]->getReportingLevelForFunction($function_id);
$level = $this->issue_handlers[$issue_type]->getReportingLevelForFunction($function_id);

if ($level === null && $issue_type === 'UndefinedFunction') {
// undefined functions trigger global namespace fallback
// so we should also check reporting levels for the symbol in global scope
$root_function_id = preg_replace('/.*\\\/', '', $function_id);
if ($root_function_id !== $function_id) {
/** @psalm-suppress PossiblyUndefinedStringArrayOffset https://github.com/vimeo/psalm/issues/7656 */
$level = $this->issue_handlers[$issue_type]->getReportingLevelForFunction($root_function_id);
}
}
}

return null;
return $level;
}

public function getReportingLevelForArgument(string $issue_type, string $function_id): ?string
Expand Down
30 changes: 30 additions & 0 deletions tests/Config/ConfigTest.php
Expand Up @@ -355,6 +355,36 @@ public function testIssueHandler(): void
$this->assertFalse($config->reportIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php')));
}

public function testGlobalUndefinedFunctionSuppression(): void
{
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
Config::loadFromXML(
dirname(__DIR__, 2),
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
<directory name="tests" />
</projectFiles>
<issueHandlers>
<UndefinedFunction>
<errorLevel type="suppress">
<referencedFunction name="zzz"/>
</errorLevel>
</UndefinedFunction>
</issueHandlers>
</psalm>'
)
);

$config = $this->project_analyzer->getConfig();
$this->assertSame(
Config::REPORT_SUPPRESS,
$config->getReportingLevelForFunction('UndefinedFunction', 'Some\Namespace\zzz')
);
}

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

0 comments on commit 293937f

Please sign in to comment.