Conditions | 9 |
Paths | 8 |
Total Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
18 | public static function fromFile($fileName) |
||
19 | { |
||
20 | if (file_exists($fileName) === false) { |
||
21 | throw new RuntimeException('Unable to locate the baseline file at: ' . $fileName); |
||
22 | } |
||
23 | |||
24 | $xml = @simplexml_load_string(file_get_contents($fileName)); |
||
25 | if ($xml === false) { |
||
26 | throw new RuntimeException('Unable to read xml from: ' . $fileName); |
||
27 | } |
||
28 | |||
29 | $basePath = dirname($fileName); |
||
30 | $baselineSet = new BaselineSet(); |
||
31 | |||
32 | foreach ($xml->children() as $node) { |
||
33 | if ($node->getName() !== 'violation') { |
||
34 | continue; |
||
35 | } |
||
36 | |||
37 | if (isset($node['rule']) === false) { |
||
38 | throw new RuntimeException('Missing `rule` attribute in `violation` in ' . $fileName); |
||
39 | } |
||
40 | |||
41 | if (isset($node['file']) === false) { |
||
42 | throw new RuntimeException('Missing `file` attribute in `violation` in ' . $fileName); |
||
43 | } |
||
44 | |||
45 | $ruleName = (string)$node['rule']; |
||
46 | $filePath = Paths::concat($basePath, (string)$node['file']); |
||
47 | $methodName = null; |
||
48 | if (isset($node['method']) === true && ((string)$node['method']) !== '') { |
||
49 | $methodName = (string)($node['method']); |
||
50 | } |
||
51 | |||
52 | $baselineSet->addEntry(new ViolationBaseline($ruleName, $filePath, $methodName)); |
||
53 | } |
||
54 | |||
55 | return $baselineSet; |
||
56 | } |
||
57 | } |
||
58 |