Conditions | 4 |
Paths | 4 |
Total Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
16 | 12 | public function validate($data, string $schema): ValidationResultInterface |
|
17 | { |
||
18 | 12 | $schemaValidator = new Validator(); |
|
19 | 12 | $schemaValidator->validate($data, json_decode($schema)); |
|
20 | |||
21 | 12 | if ($schemaValidator->isValid()) { |
|
22 | 6 | return new ValidationResult(ValidationResult::STATUS_OK); |
|
23 | } |
||
24 | |||
25 | 6 | $errors = []; |
|
26 | 6 | foreach ($schemaValidator->getErrors() as $error) { |
|
27 | 6 | $errorMessage = ''; |
|
28 | 6 | if ($error['property']) { |
|
29 | 3 | $errorMessage .= '[Property ' . $error['property'] . '] '; |
|
30 | } |
||
31 | 6 | $errorMessage .= $error['message']; |
|
32 | 6 | $errors[] = $errorMessage; |
|
33 | } |
||
34 | 6 | return new ValidationResult(ValidationResult::STATUS_ERROR, $errors); |
|
35 | } |
||
36 | } |
||
37 |