Conditions | 3 |
Paths | 3 |
Total Lines | 21 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 3 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
32 | 156 | public function validate($data, $rules) |
|
33 | { |
||
34 | 156 | $validationResult = true; |
|
35 | 156 | $this->validated = []; |
|
36 | 156 | $this->errors = []; |
|
37 | |||
38 | 156 | $dataProvider = new DataProvider($data); |
|
39 | |||
40 | 156 | foreach ($rules as $dataKey => $ruleDescription) { |
|
41 | 156 | $rule = new Rule($ruleDescription, $this->validationFactory); |
|
42 | 156 | $testedValue = $dataProvider->get($dataKey); |
|
43 | |||
44 | 156 | if ($testedValue->satisfy($rule)) { |
|
45 | 68 | $this->validated[$testedValue->alias()] = $testedValue->value(); |
|
46 | } else { |
||
47 | 96 | $this->errors[$dataKey] = $rule->errors(); |
|
48 | 96 | $validationResult = false; |
|
49 | } |
||
50 | |||
51 | } |
||
52 | 156 | return $validationResult; |
|
53 | } |
||
64 | } |