Conditions | 2 |
Paths | 1 |
Total Lines | 22 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 6 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
17 | protected function validate($input): array |
||
18 | { |
||
19 | $path = $this->getPath(); |
||
20 | $settings = $this->getSettings(); |
||
21 | $values = $settings['values'] ?? []; |
||
22 | |||
23 | Assertion::notEmpty($values, 'Permitted values must be specified.'); |
||
24 | |||
25 | Assert::that($input) |
||
26 | ->isArray('Must be an array.') |
||
27 | ->satisfy(function (array $items) use ($path, $values): void { |
||
28 | $formatAssertion = Assert::lazy(); |
||
29 | foreach ($items as $key => $item) { |
||
30 | $formatAssertion |
||
31 | ->that($item, $path) |
||
32 | ->notBlank($path."[$key] must not be blank.") |
||
33 | ->inArray($values, $path."[$key] '$item' is not a valid value."); |
||
34 | } |
||
35 | $formatAssertion->verifyNow(); |
||
36 | }); |
||
37 | |||
38 | return $input; |
||
39 | } |
||
41 |