Total Complexity | 12 |
Total Lines | 74 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
10 | class InListGuard implements Guard |
||
11 | { |
||
12 | use ErrorMessagesBase; |
||
13 | use SingleInput; |
||
14 | use Strict; |
||
15 | |||
16 | /** |
||
17 | * @var iterable |
||
18 | */ |
||
19 | private $list; |
||
20 | |||
21 | /** |
||
22 | * InListVal constructor. |
||
23 | * |
||
24 | * @param mixed $input |
||
25 | * @param iterable $list |
||
26 | * @param mixed|null $defaultValue |
||
27 | * @param bool $defaultStrict |
||
28 | * |
||
29 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||
30 | */ |
||
31 | 17 | public function __construct($input, iterable $list, $defaultValue = null, bool $defaultStrict = true) |
|
37 | 17 | } |
|
38 | |||
39 | 17 | public function value() |
|
44 | } |
||
45 | |||
46 | 17 | protected function validation($input, &$value): bool |
|
47 | { |
||
48 | 17 | if ($this->isCastable() ? $this->validateCastableList($input) : $this->validateTraversableList($input)) { |
|
|
|||
49 | 8 | $value = $input; |
|
50 | 8 | return true; |
|
51 | } |
||
52 | |||
53 | 9 | return false; |
|
54 | } |
||
55 | |||
56 | 17 | private function isCastable(): bool |
|
57 | { |
||
58 | 17 | return \is_array($this->list) || $this->list instanceof ArrayObject; |
|
59 | } |
||
60 | |||
61 | 12 | private function validateCastableList($input): bool |
|
64 | } |
||
65 | |||
66 | 5 | private function validateTraversableList($input): bool |
|
84 | } |
||
85 | } |
||
86 |