1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Restore support for namespaced functions in referencedFunction config

This commit is contained in:
Tinjo Schöni 2023-09-09 01:26:15 +02:00
parent 8362cc6900
commit 8fbe14a34b
No known key found for this signature in database
GPG Key ID: D6715103428615C4
2 changed files with 32 additions and 1 deletions

View File

@ -336,7 +336,7 @@ class FileFilter
foreach ($config['referencedFunction'] as $referenced_function) {
$function_id = $referenced_function['name'] ?? '';
if (!is_string($function_id)
|| (!preg_match('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $function_id)
|| (!preg_match('/^[a-zA-Z_\x80-\xff](?:[\\\\]?[a-zA-Z0-9_\x80-\xff]+)*$/', $function_id)
&& !preg_match('/^[^:]+::[^:]+$/', $function_id) // methods are also allowed
&& !static::isRegularExpression($function_id))) {
throw new ConfigException(

View File

@ -18,6 +18,7 @@ use Psalm\Internal\Provider\Providers;
use Psalm\Internal\RuntimeCaches;
use Psalm\Internal\Scanner\FileScanner;
use Psalm\Issue\TooManyArguments;
use Psalm\Issue\UndefinedFunction;
use Psalm\Tests\Config\Plugin\FileTypeSelfRegisteringPlugin;
use Psalm\Tests\Internal\Provider\FakeParserCacheProvider;
use Psalm\Tests\TestCase;
@ -1856,4 +1857,34 @@ class ConfigTest extends TestCase
),
);
}
public function testReferencedFunctionAllowsNamespacedFunctions(): void
{
$config_xml = Config::loadFromXML(
(string) getcwd(),
<<<XML
<?xml version="1.0"?>
<psalm>
<issueHandlers>
<UndefinedFunction>
<errorLevel type="suppress">
<referencedFunction name="Foo\Bar\baz" />
</errorLevel>
</UndefinedFunction>
</issueHandlers>
</psalm>
XML,
);
$this->assertSame(
Config::REPORT_SUPPRESS,
$config_xml->getReportingLevelForIssue(
new UndefinedFunction(
'Function Foo\Bar\baz does not exist',
new Raw('aaa', 'aaa.php', 'aaa.php', 1, 2),
'foo\bar\baz',
),
),
);
}
}