| Conditions | 3 |
| Paths | 3 |
| Total Lines | 22 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | 8 | public function validate(string $jsonString): ValidationResult |
|
| 35 | { |
||
| 36 | 8 | $this->validator->reset(); |
|
| 37 | |||
| 38 | 8 | $validationResult = new ValidationResult(); |
|
| 39 | 8 | $decodedJson = json_decode($jsonString); |
|
| 40 | |||
| 41 | 8 | if (null === $decodedJson) { |
|
| 42 | 2 | $validationResult->addViolation(ValidationViolation::create('Not a JSON or invalid format')); |
|
| 43 | |||
| 44 | 2 | return $validationResult; |
|
| 45 | } |
||
| 46 | |||
| 47 | try { |
||
| 48 | 6 | $this->validator->check($decodedJson, $this->schema); |
|
| 49 | 1 | } catch (\Exception $e) { |
|
| 50 | 1 | $validationResult->addViolation(ValidationViolation::create(sprintf('Validator check exception: "%s"', $e->getMessage()))); |
|
| 51 | } |
||
| 52 | |||
| 53 | 6 | $this->mapErrorsToResultViolations($validationResult); |
|
| 54 | |||
| 55 | 6 | return $validationResult; |
|
| 56 | } |
||
| 68 |