mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #1225 - ignore classes using patterns
This commit is contained in:
parent
075446e7df
commit
930a8b2689
@ -20,6 +20,11 @@ class FileFilter
|
||||
*/
|
||||
protected $fq_classlike_names = [];
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $fq_classlike_patterns = [];
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
@ -234,7 +239,14 @@ class FileFilter
|
||||
if ($e->referencedClass) {
|
||||
/** @var \SimpleXMLElement $referenced_class */
|
||||
foreach ($e->referencedClass as $referenced_class) {
|
||||
$filter->fq_classlike_names[] = strtolower((string)$referenced_class['name']);
|
||||
$class_name = strtolower((string)$referenced_class['name']);
|
||||
|
||||
if (strpos($class_name, '*')) {
|
||||
$regex = '/' . \str_replace('*', '.*', str_replace('\\', '\\\\', $class_name)) . '/i';
|
||||
$filter->fq_classlike_patterns[] = $regex;
|
||||
} else {
|
||||
$filter->fq_classlike_names[] = $class_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,6 +358,14 @@ class FileFilter
|
||||
*/
|
||||
public function allowsClass($fq_classlike_name)
|
||||
{
|
||||
if ($this->fq_classlike_patterns) {
|
||||
foreach ($this->fq_classlike_patterns as $pattern) {
|
||||
if (preg_match($pattern, $fq_classlike_name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return in_array(strtolower($fq_classlike_name), $this->fq_classlike_names);
|
||||
}
|
||||
|
||||
|
@ -344,6 +344,7 @@ class ConfigTest extends TestCase
|
||||
<UndefinedClass>
|
||||
<errorLevel type="suppress">
|
||||
<referencedClass name="Psalm\Badger" />
|
||||
<referencedClass name="Psalm\*Actor" />
|
||||
</errorLevel>
|
||||
</UndefinedClass>
|
||||
<UndefinedMethod>
|
||||
@ -393,6 +394,22 @@ class ConfigTest extends TestCase
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'suppress',
|
||||
$config->getReportingLevelForClass(
|
||||
'UndefinedClass',
|
||||
'Psalm\BadActor'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'suppress',
|
||||
$config->getReportingLevelForClass(
|
||||
'UndefinedClass',
|
||||
'Psalm\GoodActor'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'error',
|
||||
$config->getReportingLevelForClass(
|
||||
|
Loading…
x
Reference in New Issue
Block a user