Conditions | 3 |
Paths | 3 |
Total Lines | 17 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
20 | public function validate(Json $json, Validator $validator, SchemaStorage $schemaStorage) |
||
21 | { |
||
22 | $schema = $schemaStorage->resolveRef('file://' . realpath($this->filename)); |
||
23 | $data = $json->getRawContent(); |
||
24 | |||
25 | $validator->check($data, $schema); |
||
26 | |||
27 | if (!$validator->isValid()) { |
||
28 | $msg = "JSON does not validate. Violations:" . PHP_EOL; |
||
29 | foreach ($validator->getErrors() as $error) { |
||
30 | $msg .= sprintf(" - [%s] %s" . PHP_EOL, $error['property'], $error['message']); |
||
31 | } |
||
32 | throw new \Exception($msg); |
||
33 | } |
||
34 | |||
35 | return true; |
||
36 | } |
||
37 | } |
||
38 |