mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Honour global function suppressions for UndefinedFunction
Fixes vimeo/psalm#7610
This commit is contained in:
parent
a3852b8a55
commit
45a19b3f3c
@ -1790,11 +1790,21 @@ class Config
|
||||
|
||||
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) {
|
||||
$level = $this->issue_handlers[$issue_type]->getReportingLevelForFunction($root_function_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return $level;
|
||||
}
|
||||
|
||||
public function getReportingLevelForArgument(string $issue_type, string $function_id): ?string
|
||||
|
@ -355,6 +355,36 @@ class ConfigTest extends TestCase
|
||||
$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(
|
||||
|
Loading…
Reference in New Issue
Block a user