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