Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
ListChoiceTester | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setChoices | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getChoices | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
testValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
5 | */ |
6 | declare(strict_types=1); |
7 | |
8 | namespace pvc\validator\val_tester\list_choice; |
9 | |
10 | use pvc\interfaces\validator\ValTesterInterface; |
11 | |
12 | /** |
13 | * Class ListChoiceValTester |
14 | * @implements ValTesterInterface<mixed> |
15 | */ |
16 | class ListChoiceTester implements ValTesterInterface |
17 | { |
18 | /** |
19 | * @var array<mixed> |
20 | */ |
21 | protected array $choices; |
22 | |
23 | /** |
24 | * @param array<mixed> $choices |
25 | */ |
26 | public function __construct(array $choices) |
27 | { |
28 | $this->setChoices($choices); |
29 | } |
30 | |
31 | /** |
32 | * setChoices |
33 | * @param array<mixed> $choices |
34 | */ |
35 | public function setChoices(array $choices): void |
36 | { |
37 | $this->choices = $choices; |
38 | } |
39 | |
40 | /** |
41 | * getChoices |
42 | * @return mixed[] |
43 | */ |
44 | public function getChoices(): array |
45 | { |
46 | return $this->choices; |
47 | } |
48 | |
49 | /** |
50 | * testValue |
51 | * @param mixed $value |
52 | * @return bool |
53 | */ |
54 | public function testValue(mixed $value): bool |
55 | { |
56 | /** use the strict parameter set to true - see in_array documentation for why */ |
57 | return in_array($value, $this->choices, true); |
58 | } |
59 | } |