mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Add support for regexes as referencedMethods
This commit is contained in:
parent
6e010d9db9
commit
a86bbad796
@ -273,7 +273,7 @@ class FileFilter
|
||||
foreach ($e->referencedMethod as $referenced_method) {
|
||||
$method_id = (string)$referenced_method['name'];
|
||||
|
||||
if (!preg_match('/^[^:]+::[^:]+$/', $method_id)) {
|
||||
if (!preg_match('/^[^:]+::[^:]+$/', $method_id) && !static::isRegularExpression($method_id)) {
|
||||
echo 'Invalid referencedMethod ' . $method_id . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
@ -299,6 +299,19 @@ class FileFilter
|
||||
return $filter;
|
||||
}
|
||||
|
||||
private static function isRegularExpression(string $string) : bool
|
||||
{
|
||||
set_error_handler(
|
||||
function () : bool {
|
||||
return false;
|
||||
},
|
||||
E_WARNING
|
||||
);
|
||||
$is_regexp = preg_match($string, "") !== FALSE;
|
||||
restore_error_handler();
|
||||
return $is_regexp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
*
|
||||
@ -394,13 +407,30 @@ class FileFilter
|
||||
*/
|
||||
public function allowsMethod($method_id)
|
||||
{
|
||||
if (!$this->method_ids) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (preg_match('/^[^:]+::[^:]+$/', $method_id)) {
|
||||
$method_stub = '*::' . explode('::', $method_id)[1];
|
||||
|
||||
if (in_array($method_stub, $this->method_ids)) {
|
||||
return true;
|
||||
foreach ($this->method_ids as $config_method_id) {
|
||||
if ($config_method_id === $method_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($config_method_id === $method_stub) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($config_method_id[0] === '/' && preg_match($config_method_id, $method_id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array($method_id, $this->method_ids);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user