Total Complexity | 14 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
8 | class BoolGuard implements Guard |
||
9 | { |
||
10 | use ErrorMessagesBase; |
||
11 | use SingleInput; |
||
12 | |||
13 | /** |
||
14 | * @var bool |
||
15 | */ |
||
16 | private $pseudoBools = false; |
||
17 | |||
18 | 19 | public function __construct($input, ?bool $default = null) |
|
19 | { |
||
20 | 19 | $this->input = $input; |
|
21 | 19 | $this->value = $default; |
|
22 | 19 | } |
|
23 | |||
24 | 10 | public function allowPseudoBools(): self |
|
25 | { |
||
26 | 10 | $this->pseudoBools = true; |
|
27 | |||
28 | 10 | return $this; |
|
29 | } |
||
30 | |||
31 | 17 | public function value(): ?bool |
|
36 | } |
||
37 | |||
38 | 18 | protected function validation($input, &$value): bool |
|
49 | } |
||
50 | |||
51 | 18 | private function isTrue($input): bool |
|
52 | { |
||
53 | 18 | return $input === true || $this->isPseudoTrue($input); |
|
54 | } |
||
55 | |||
56 | 17 | private function isPseudoTrue($input): bool |
|
57 | { |
||
58 | 17 | return $this->pseudoBools && \in_array($input, [1, '1'], true); |
|
59 | } |
||
60 | |||
61 | 15 | private function isFalse($input): bool |
|
64 | } |
||
65 | |||
66 | 12 | private function isPseudoFalse($input): bool |
|
69 | } |
||
70 | } |
||
71 |