1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Merge pull request #7657 from weirdan/fix-7610

This commit is contained in:
Bruce Weirdan 2022-02-13 01:32:21 +02:00 committed by GitHub
commit 293937fbc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 2 deletions

View File

@ -1790,11 +1790,22 @@ class Config
public function getReportingLevelForFunction(string $issue_type, string $function_id): ?string public function getReportingLevelForFunction(string $issue_type, string $function_id): ?string
{ {
$level = null;
if (isset($this->issue_handlers[$issue_type])) { 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 public function getReportingLevelForArgument(string $issue_type, string $function_id): ?string

View File

@ -355,6 +355,36 @@ class ConfigTest extends TestCase
$this->assertFalse($config->reportIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php'))); $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 public function testMultipleIssueHandlers(): void
{ {
$this->project_analyzer = $this->getProjectAnalyzerWithConfig( $this->project_analyzer = $this->getProjectAnalyzerWithConfig(