| Total Complexity | 7 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Coverage | 68.42% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | class Each extends Rule |
||
| 19 | { |
||
| 20 | use HasValidationErrorMessage; |
||
| 21 | |||
| 22 | private Rules $rules; |
||
| 23 | |||
| 24 | private string $incorrectInputMessage = 'Value should be array or iterable'; |
||
| 25 | private string $message = '{error} {value} given.'; |
||
| 26 | |||
| 27 | 5 | public function __construct(Rules $rules) |
|
| 30 | 5 | } |
|
| 31 | |||
| 32 | 2 | protected function validateValue($value, DataSetInterface $dataSet = null): Result |
|
| 33 | { |
||
| 34 | 2 | $result = new Result(); |
|
| 35 | 2 | if (!is_iterable($value)) { |
|
| 36 | $result->addError(new ErrorMessage($this->incorrectInputMessage)); |
||
| 37 | return $result; |
||
| 38 | } |
||
| 39 | |||
| 40 | 2 | foreach ($value as $item) { |
|
| 41 | 2 | $itemResult = $this->rules->validate($item, $dataSet); |
|
| 42 | 2 | if ($itemResult->isValid() === false) { |
|
| 43 | 2 | $result->addResultWithWrapper($itemResult, $this->message, ['value' => $item]); |
|
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | 2 | return $result; |
|
| 48 | } |
||
| 49 | |||
| 50 | public function incorrectInputMessage(string $message): self |
||
| 55 | } |
||
| 56 | |||
| 57 | 2 | public function getOptions(?ErrorMessageFormatterInterface $formatter = null): array |
|
| 60 | } |
||
| 61 | } |
||
| 62 |