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