Skip to content

Commit

Permalink
Merge pull request #10186 from tscni/fix/referenced-function-ns
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Sep 9, 2023
2 parents 8362cc6 + 8fbe14a commit f782767
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Psalm/Config/FileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public static function loadFromArray(
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(
Expand Down
31 changes: 31 additions & 0 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;
Expand Down Expand Up @@ -1856,4 +1857,34 @@ public function testReferencedFunctionAllowsMethods(): void
),
);
}

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',
),
),
);
}
}

0 comments on commit f782767

Please sign in to comment.