Conditions | 7 |
Paths | 8 |
Total Lines | 30 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 7 |
Changes | 0 |
1 | <?php |
||
46 | 17 | protected function validation($input, &$value): bool |
|
47 | { |
||
48 | // If the input is an array or an ArrayObject then it's cheap to cast it and use in_array(). |
||
49 | 17 | if (\is_array($this->list) || $this->list instanceof ArrayObject) { |
|
50 | 12 | if (\in_array($input, (array)$this->list, $this->strict)) { |
|
51 | 6 | $value = $input; |
|
52 | 6 | return true; |
|
53 | } |
||
54 | |||
55 | 6 | return false; |
|
56 | } |
||
57 | |||
58 | 5 | $validate = $this->strict |
|
59 | ? function ($value) use ($input): bool { |
||
60 | 3 | return $value === $input; |
|
61 | 3 | } |
|
62 | : function ($value) use ($input): bool { |
||
63 | /** @noinspection TypeUnsafeComparisonInspection */ |
||
64 | 2 | return $value == $input; |
|
65 | 5 | }; |
|
66 | |||
67 | // Since the type hint is 'iterable' (aka Traversable) iterate over the object. |
||
68 | 5 | foreach ($this->list as $item) { |
|
69 | 5 | if ($validate($item)) { |
|
70 | 2 | $value = $input; |
|
71 | 5 | return true; |
|
72 | } |
||
73 | } |
||
74 | |||
75 | 3 | return false; |
|
76 | } |
||
78 |