Conditions | 3 |
Paths | 8 |
Total Lines | 24 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 3 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | 2 | public function validate(string $xmlString): ValidationResult |
|
23 | { |
||
24 | 2 | $validationResult = new ValidationResult(); |
|
25 | 2 | $useInternalErrors = libxml_use_internal_errors(); |
|
26 | |||
27 | 2 | libxml_use_internal_errors(true); |
|
28 | 2 | libxml_clear_errors(); |
|
29 | |||
30 | try { |
||
31 | 2 | $document = $this->createDOMDocument($xmlString); |
|
32 | |||
33 | 2 | if ($document->schemaValidateSource(file_get_contents($this->schemaLocation))) { |
|
34 | 1 | return $validationResult; |
|
35 | } |
||
36 | |||
37 | /** @var \LibXMLError $error */ |
||
38 | 1 | foreach (libxml_get_errors() as $error) { |
|
39 | 1 | $validationResult->addViolation(ValidationViolation::create($error->message, 'line '.$error->line)); |
|
40 | } |
||
41 | |||
42 | 1 | return $validationResult; |
|
43 | } finally { |
||
44 | 2 | libxml_clear_errors(); |
|
45 | 2 | libxml_use_internal_errors($useInternalErrors); |
|
46 | } |
||
66 |