Skip to content

Commit

Permalink
Merge pull request #10071 from weirdan/fix-10070
Browse files Browse the repository at this point in the history
Allow method-like strings in `referencedFunction`
  • Loading branch information
orklah authored Aug 1, 2023
2 parents b2942ce + ec842c0 commit b9d355e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Psalm/Config/FileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ public static function loadFromArray(
$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('/^[^:]+::[^:]+$/', $function_id) // methods are also allowed
&& !static::isRegularExpression($function_id))) {
throw new ConfigException(
'Invalid referencedFunction ' . ((string) $function_id),
Expand Down
32 changes: 32 additions & 0 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\Autoload\ClassLoader;
use ErrorException;
use Psalm\CodeLocation\Raw;
use Psalm\Config;
use Psalm\Config\IssueHandler;
use Psalm\Context;
Expand All @@ -16,6 +17,7 @@
use Psalm\Internal\Provider\Providers;
use Psalm\Internal\RuntimeCaches;
use Psalm\Internal\Scanner\FileScanner;
use Psalm\Issue\TooManyArguments;
use Psalm\Tests\Config\Plugin\FileTypeSelfRegisteringPlugin;
use Psalm\Tests\Internal\Provider\FakeParserCacheProvider;
use Psalm\Tests\TestCase;
Expand Down Expand Up @@ -1824,4 +1826,34 @@ public function testConfigWithDisableExtensionsDoesNotLoadExtensionStubsAndHides
$config->internal_stubs,
);
}

public function testReferencedFunctionAllowsMethods(): void
{
$config_xml = Config::loadFromXML(
(string) getcwd(),
<<<XML
<?xml version="1.0"?>
<psalm>
<issueHandlers>
<TooManyArguments>
<errorLevel type="suppress">
<referencedFunction name="Foo\Bar::baz" />
</errorLevel>
</TooManyArguments>
</issueHandlers>
</psalm>
XML,
);

$this->assertSame(
Config::REPORT_SUPPRESS,
$config_xml->getReportingLevelForIssue(
new TooManyArguments(
'too many',
new Raw('aaa', 'aaa.php', 'aaa.php', 1, 2),
'Foo\Bar::baZ',
),
),
);
}
}

0 comments on commit b9d355e

Please sign in to comment.