From 8fbe14a34b4cec64ce9d3e96aad7056a026e493e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tinjo=20Sch=C3=B6ni?= <32767367+tscni@users.noreply.github.com> Date: Sat, 9 Sep 2023 01:26:15 +0200 Subject: [PATCH] Restore support for namespaced functions in referencedFunction config --- src/Psalm/Config/FileFilter.php | 2 +- tests/Config/ConfigTest.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Config/FileFilter.php b/src/Psalm/Config/FileFilter.php index 8ca440947..4ef5f993c 100644 --- a/src/Psalm/Config/FileFilter.php +++ b/src/Psalm/Config/FileFilter.php @@ -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( diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php index da14fa40f..c4b682967 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Config/ConfigTest.php @@ -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, + ); + + $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', + ), + ), + ); + } }