/
ErrorLevelFileFilter.php
66 lines (53 loc) · 1.65 KB
/
ErrorLevelFileFilter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Psalm\Config;
use Psalm\Config;
use Psalm\Exception\ConfigException;
use SimpleXMLElement;
use function in_array;
/** @internal */
final class ErrorLevelFileFilter extends FileFilter
{
private string $error_level = '';
/**
* @return static
*/
public static function loadFromArray(
array $config,
string $base_dir,
bool $inclusive
): ErrorLevelFileFilter {
$filter = parent::loadFromArray($config, $base_dir, $inclusive);
if (isset($config['type'])) {
$filter->error_level = (string) $config['type'];
if (!in_array($filter->error_level, Config::$ERROR_LEVELS, true)) {
throw new ConfigException('Unexpected error level ' . $filter->error_level);
}
} else {
throw new ConfigException('<type> element expects a level');
}
return $filter;
}
/**
* @return static
*/
public static function loadFromXMLElement(
SimpleXMLElement $e,
string $base_dir,
bool $inclusive
): ErrorLevelFileFilter {
$filter = parent::loadFromXMLElement($e, $base_dir, $inclusive);
if (isset($e['type'])) {
$filter->error_level = (string) $e['type'];
if (!in_array($filter->error_level, Config::$ERROR_LEVELS, true)) {
throw new ConfigException('Unexpected error level ' . $filter->error_level);
}
} else {
throw new ConfigException('<type> element expects a level');
}
return $filter;
}
public function getErrorLevel(): string
{
return $this->error_level;
}
}