| Conditions | 4 |
| Paths | 6 |
| Total Lines | 28 |
| Code Lines | 16 |
| Lines | 4 |
| Ratio | 14.29 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | protected function doValidation(Response $response) |
||
| 24 | { |
||
| 25 | $body = $response->getBody(); |
||
| 26 | |||
| 27 | $dom = new \DOMDocument(); |
||
| 28 | @$dom->loadXML($body); |
||
|
|
|||
| 29 | |||
| 30 | $filename = (string)$response->getUri(); |
||
| 31 | |||
| 32 | $error = false; |
||
| 33 | $messageParts = array(); |
||
| 34 | |||
| 35 | foreach ($this->xsdFiles AS $xsdFile) { |
||
| 36 | $valid = @$dom->schemaValidate($xsdFile['xsdfileurl']); |
||
| 37 | |||
| 38 | if (!$valid) { |
||
| 39 | $error = true; |
||
| 40 | $lastError = libxml_get_last_error(); |
||
| 41 | |||
| 42 | $messageParts[] = $xsdFile['xsdfilename'] . ' - ' . $xsdFile['xsdfileurl'] . '(last error: ' . str_replace("\n", '', $lastError->message) . ').'; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | View Code Duplication | if ($error === true) { |
|
| 47 | $message = 'XML file (' . $filename . ') does not validate against the following XSD files: ' . implode(", ", $messageParts); |
||
| 48 | throw new ValidationFailedException($message); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } |
||
| 52 |
If you suppress an error, we recommend checking for the error condition explicitly: