| Conditions | 2 |
| Paths | 2 |
| Total Lines | 24 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 2 |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 14 | 2 | public static function withValidationErrors(ValidationError ...$errors): self |
|
| 15 | { |
||
| 16 | 2 | $messages = \array_map( |
|
| 17 | function(ValidationError $error) { |
||
| 18 | 2 | return \sprintf( |
|
| 19 | 2 | 'Error: [%s], Data pointer: [%s]', |
|
| 20 | 2 | $error->keyword(), |
|
| 21 | 2 | \implode(', ', $error->dataPointer()), |
|
| 22 | ); |
||
| 23 | 2 | }, |
|
| 24 | 2 | $errors |
|
| 25 | ); |
||
| 26 | |||
| 27 | 2 | $instance = new self( |
|
| 28 | 2 | \sprintf('Json schema validation failed: %s', \implode(', ', $messages)) |
|
| 29 | ); |
||
| 30 | |||
| 31 | 2 | $instance->errors = $errors; |
|
| 32 | 2 | $instance->errorMapping = ArrayAccess::create([]); |
|
| 33 | 2 | foreach ($errors as $error) { |
|
| 34 | 2 | $instance->errorMapping = $instance->errorMapping->writeAtPath((string) $error->keyword(), ...$error->dataPointer()); |
|
| 35 | } |
||
| 36 | |||
| 37 | 2 | return $instance; |
|
| 38 | } |
||
| 44 | } |