| Conditions | 5 |
| Paths | 12 |
| Total Lines | 22 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 5.0592 |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | 4 | public function validate(DataSetInterface $dataSet, iterable $rules = []): ResultSet |
|
| 27 | { |
||
| 28 | 4 | if ($dataSet instanceof RulesProviderInterface) { |
|
| 29 | /** @noinspection CallableParameterUseCaseInTypeContextInspection */ |
||
| 30 | 2 | $rules = $dataSet->getRules(); |
|
| 31 | } |
||
| 32 | 4 | $context = new ValidationContext($dataSet); |
|
| 33 | 4 | $resultSet = new ResultSet(); |
|
| 34 | 4 | foreach ($rules as $attribute => $attributeRules) { |
|
| 35 | 4 | $aggregateRule = new Rules($attributeRules); |
|
| 36 | 4 | if ($this->formatter !== null) { |
|
| 37 | $aggregateRule = $aggregateRule->withFormatter($this->formatter); |
||
| 38 | } |
||
| 39 | 4 | $resultSet->addResult( |
|
| 40 | 4 | $attribute, |
|
| 41 | 4 | $aggregateRule->validate($dataSet->getAttributeValue($attribute), $context->withAttribute($attribute)) |
|
| 42 | ); |
||
| 43 | } |
||
| 44 | 4 | if ($dataSet instanceof PostValidationHookInterface) { |
|
| 45 | $dataSet->processValidationResult($resultSet); |
||
| 46 | } |
||
| 47 | 4 | return $resultSet; |
|
| 48 | } |
||
| 57 |