Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
10 / 10 |
CRAP | |
100.00% |
1 / 1 |
| FilterVarTester | |
100.00% |
17 / 17 |
|
100.00% |
10 / 10 |
11 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFilterVar | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setFilterVar | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setFilter | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getFilter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setLabel | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getLabel | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| addOption | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| addFlag | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| testValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
| 4 | */ |
| 5 | |
| 6 | declare(strict_types=1); |
| 7 | |
| 8 | namespace pvc\validator\val_tester\filter_var; |
| 9 | |
| 10 | use pvc\interfaces\filtervar\FilterVarValidateInterface; |
| 11 | use pvc\interfaces\validator\ValTesterInterface; |
| 12 | use pvc\validator\err\InvalidLabelException; |
| 13 | |
| 14 | /** |
| 15 | * Class FilterVarTester |
| 16 | * @implements ValTesterInterface<string> |
| 17 | * filter_var is a php verb that can be used either to validate a string or to sanitize a string. This object |
| 18 | * wants to use filter_var for validation of course. So in essence, this class wraps the FilterVarValidate class |
| 19 | * and provides convenience methods to set flags, options, etc. |
| 20 | */ |
| 21 | class FilterVarTester implements ValTesterInterface |
| 22 | { |
| 23 | public function __construct(FilterVarValidateInterface $filterVarValidate) |
| 24 | { |
| 25 | $this->setFilterVar($filterVarValidate); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @var FilterVarValidateInterface |
| 30 | */ |
| 31 | protected FilterVarValidateInterface $filterVar; |
| 32 | |
| 33 | /** |
| 34 | * getFilterVar |
| 35 | * @return FilterVarValidateInterface |
| 36 | */ |
| 37 | public function getFilterVar(): FilterVarValidateInterface |
| 38 | { |
| 39 | return $this->filterVar; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * setFilterVar |
| 44 | * @param FilterVarValidateInterface $filterVar |
| 45 | * @return $this |
| 46 | */ |
| 47 | public function setFilterVar(FilterVarValidateInterface $filterVar): FilterVarTester |
| 48 | { |
| 49 | $this->filterVar = $filterVar; |
| 50 | return $this; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * setFilter |
| 55 | * @param int $filter |
| 56 | * @return $this |
| 57 | */ |
| 58 | public function setFilter(int $filter): FilterVarTester |
| 59 | { |
| 60 | $this->getFilterVar()->setFilter($filter); |
| 61 | return $this; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * getFilter |
| 66 | * @return int |
| 67 | */ |
| 68 | public function getFilter(): int |
| 69 | { |
| 70 | return $this->getFilterVar()->getFilter(); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * setLabel |
| 75 | * @param string $label |
| 76 | * @return $this |
| 77 | * @throws InvalidLabelException |
| 78 | */ |
| 79 | public function setLabel(string $label): FilterVarTester |
| 80 | { |
| 81 | if (empty($label)) { |
| 82 | throw new InvalidLabelException(); |
| 83 | } |
| 84 | $this->getFilterVar()->setLabel($label); |
| 85 | return $this; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * getLabel |
| 90 | * @return string |
| 91 | */ |
| 92 | public function getLabel(): string |
| 93 | { |
| 94 | return $this->getFilterVar()->getLabel(); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * addOption |
| 99 | * @param string $filterVarOption |
| 100 | */ |
| 101 | public function addOption(string $filterVarOption, mixed $value): FilterVarTester |
| 102 | { |
| 103 | $this->filterVar->addOption($filterVarOption, $value); |
| 104 | return $this; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * addFlag |
| 109 | * @param int $filterFlag |
| 110 | * @return $this |
| 111 | */ |
| 112 | public function addFlag(int $filterFlag): FilterVarTester |
| 113 | { |
| 114 | $this->filterVar->addFlag($filterFlag); |
| 115 | return $this; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @function testValue |
| 120 | * @param string $value |
| 121 | * @return bool |
| 122 | */ |
| 123 | public function testValue(mixed $value = ''): bool |
| 124 | { |
| 125 | return $this->getFilterVar()->validate($value); |
| 126 | } |
| 127 | } |