| Conditions | 3 |
| Paths | 3 |
| Total Lines | 23 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 3.3332 |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | 1 | public function validate(string $jsonString): ValidationResult |
|
| 28 | { |
||
| 29 | 1 | $this->validator->reset(); |
|
| 30 | |||
| 31 | 1 | $validationResult = new ValidationResult(); |
|
| 32 | 1 | $decodedJson = json_decode($jsonString); |
|
| 33 | |||
| 34 | 1 | if (null === $decodedJson) { |
|
| 35 | $validationResult->addViolation(ValidationViolation::create('Not a JSON or invalid format')); |
||
| 36 | |||
| 37 | return $validationResult; |
||
| 38 | } |
||
| 39 | |||
| 40 | try { |
||
| 41 | 1 | $this->validator->check($decodedJson, $this->schema); |
|
| 42 | } catch (\Exception $e) { |
||
| 43 | $validationResult->addViolation(ValidationViolation::create($e->getMessage())); |
||
| 44 | } |
||
| 45 | |||
| 46 | 1 | $this->mapErrorsToResultViolations($this->validator, $validationResult); |
|
| 47 | |||
| 48 | 1 | return $validationResult; |
|
| 49 | } |
||
| 50 | |||
| 58 |