Conditions | 3 |
Paths | 3 |
Total Lines | 18 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 3 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | 15 | public function validate(ValidatableModelInterface $model, array $data): array |
|
13 | { |
||
14 | 15 | $rules = $this->prepareRules( |
|
15 | 15 | $data, |
|
16 | 15 | $model->getRules(), |
|
17 | 15 | $model->getOptionalFields(), |
|
|
|||
18 | 15 | $model instanceof StrictValidatableModelInterface |
|
19 | ); |
||
20 | |||
21 | 15 | $errors = []; |
|
22 | 15 | foreach ($rules as $field => $fieldRules) { |
|
23 | 10 | $result = (new Rules($fieldRules))->validate(ArrayHelper::getValueByPath($data, $field)); |
|
24 | 10 | if ($result->isValid() === false) { |
|
25 | 4 | $errors[$field] = $result->getErrors(); |
|
26 | } |
||
27 | } |
||
28 | |||
29 | 15 | return $errors; |
|
30 | } |
||
53 |