| Total Complexity | 4 |
| Total Lines | 22 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class ToDoValidator |
||
| 11 | { |
||
| 12 | public function __construct( |
||
| 13 | private ValidatorInterface $validator |
||
|
|
|||
| 14 | ) { |
||
| 15 | } |
||
| 16 | |||
| 17 | public function validate(ToDo $toDo): void |
||
| 18 | { |
||
| 19 | $errors = $this->validator->validate($toDo); |
||
| 20 | |||
| 21 | if ($errors->count() === 0) { |
||
| 22 | return; |
||
| 23 | } |
||
| 24 | |||
| 25 | $errorMessages = []; |
||
| 26 | foreach ($errors as $error) { |
||
| 27 | assert($error instanceof ConstraintViolation); |
||
| 28 | $errorMessages[] = sprintf('%s: %s', $error->getPropertyPath(), $error->getMessage()); |
||
| 29 | } |
||
| 30 | |||
| 31 | throw new BadRequestHttpException(json_encode($errorMessages, JSON_THROW_ON_ERROR)); |
||
| 32 | } |
||
| 34 |