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