| Conditions | 5 |
| Paths | 5 |
| Total Lines | 16 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 32 | 6 | public function validate(array $data): bool |
|
| 33 | { |
||
| 34 | 6 | $this->errors = []; |
|
| 35 | |||
| 36 | 6 | foreach ($this->requiredFields as $field) { |
|
| 37 | 6 | $fieldValue = $data[$field] ?? null; |
|
| 38 | 6 | $isFieldEmpty = empty($fieldValue); |
|
| 39 | $isFieldArrayWithEmptyValues = is_array($fieldValue) && array_filter($fieldValue) === []; |
||
| 40 | 6 | ||
| 41 | 4 | if ($isFieldEmpty || $isFieldArrayWithEmptyValues) { |
|
| 42 | 4 | $msg = ucwords(str_replace('_', ' ', $field)); |
|
| 43 | $this->errors[$field] = $msg . ' is required.'; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | 6 | ||
| 47 | return empty($this->errors); // Validation passed if no errors |
||
| 48 | } |
||
| 58 |