Conditions | 3 |
Paths | 10 |
Total Lines | 30 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 3.0494 |
Changes | 0 |
1 | <?php |
||
24 | 1 | public function validate(string $xmlString): ValidationResult |
|
25 | { |
||
26 | 1 | $validationResult = new ValidationResult(); |
|
27 | 1 | $useInternalErrors = libxml_use_internal_errors(); |
|
28 | |||
29 | 1 | libxml_use_internal_errors(true); |
|
30 | 1 | libxml_clear_errors(); |
|
31 | |||
32 | try { |
||
33 | 1 | $doc = new \DOMDocument(); |
|
34 | 1 | $doc->preserveWhiteSpace = true; |
|
35 | 1 | $doc->formatOutput = true; |
|
36 | 1 | $doc->recover = true; |
|
37 | |||
38 | 1 | $doc->loadXML($xmlString); |
|
39 | |||
40 | 1 | if ($doc->schemaValidateSource(file_get_contents($this->schemaLocation))) { |
|
41 | 1 | return $validationResult; |
|
42 | } |
||
43 | |||
44 | foreach (libxml_get_errors() as $error) { |
||
45 | $validationResult->addViolation(ValidationViolation::create($error->message, 'line '.$error->line)); |
||
46 | } |
||
47 | |||
48 | return $validationResult; |
||
49 | } finally { |
||
50 | 1 | libxml_clear_errors(); |
|
51 | 1 | libxml_use_internal_errors($useInternalErrors); |
|
52 | } |
||
53 | } |
||
54 | } |
||
55 |