| Conditions | 3 |
| Paths | 3 |
| Total Lines | 15 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 3 |
| Changes | 8 | ||
| Bugs | 1 | Features | 2 |
| 1 | <?php |
||
| 23 | public function validate(HttpInputValidator $validator, ?Data &$input = null): ?Response |
||
| 24 | 4 | { |
|
| 25 | $input ??= new Immutable($this->getParsedBody() ?? []); |
||
|
|
|||
| 26 | 4 | if (0 === $input->count()) { |
|
| 27 | $errors = ['validate' => 'Nothing to validate', 'code' => HttpStatus::BAD_REQUEST]; |
||
| 28 | 4 | return new JsonResponse($errors, HttpStatus::BAD_REQUEST, [ |
|
| 29 | 1 | 'Content-Type' => 'application/problem+json' |
|
| 30 | ]); |
||
| 31 | } |
||
| 32 | 3 | if (empty($errors = $validator->validate($input))) { |
|
| 33 | 1 | return null; |
|
| 34 | } |
||
| 35 | $errors['status'] = (int)($errors['status'] ?? HttpStatus::BAD_REQUEST); |
||
| 36 | 2 | return new JsonResponse($errors, $errors['status'], [ |
|
| 37 | 2 | 'Content-Type' => 'application/problem+json' |
|
| 38 | ]); |
||
| 41 |