Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
RegexTester | |
100.00% |
13 / 13 |
|
100.00% |
8 / 8 |
9 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLabel | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRegex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setRegex | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setPattern | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getPattern | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setLabel | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
testValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
5 | */ |
6 | |
7 | declare(strict_types=1); |
8 | |
9 | namespace pvc\validator\val_tester\regex; |
10 | |
11 | use pvc\interfaces\regex\RegexInterface; |
12 | use pvc\interfaces\validator\ValTesterInterface; |
13 | use pvc\validator\err\InvalidLabelException; |
14 | |
15 | /** |
16 | * Class ValidatorRegex |
17 | * @implements ValTesterInterface<string> |
18 | */ |
19 | class RegexTester implements ValTesterInterface |
20 | { |
21 | /** |
22 | * @var RegexInterface |
23 | */ |
24 | protected RegexInterface $regex; |
25 | |
26 | public function __construct(RegexInterface $regex) |
27 | { |
28 | $this->setRegex($regex); |
29 | } |
30 | |
31 | /** |
32 | * getLabel |
33 | * @return string |
34 | */ |
35 | public function getLabel(): string |
36 | { |
37 | return $this->getRegex()->getLabel(); |
38 | } |
39 | |
40 | /** |
41 | * @return RegexInterface |
42 | */ |
43 | public function getRegex(): RegexInterface |
44 | { |
45 | return $this->regex; |
46 | } |
47 | |
48 | /** |
49 | * @function setRegex |
50 | * @param RegexInterface $regex |
51 | */ |
52 | public function setRegex(RegexInterface $regex): RegexTester |
53 | { |
54 | $this->regex = $regex; |
55 | return $this; |
56 | } |
57 | |
58 | /** |
59 | * setPattern |
60 | * @param string $pattern |
61 | */ |
62 | public function setPattern(string $pattern): RegexTester |
63 | { |
64 | $this->getRegex()->setPattern($pattern); |
65 | return $this; |
66 | } |
67 | |
68 | /** |
69 | * getPattern |
70 | * @return string |
71 | */ |
72 | public function getPattern(): string |
73 | { |
74 | return $this->getRegex()->getPattern(); |
75 | } |
76 | |
77 | /** |
78 | * setLabel |
79 | * @param string $label |
80 | */ |
81 | public function setLabel(string $label): RegexTester |
82 | { |
83 | if (empty($label)) { |
84 | throw new InvalidLabelException(); |
85 | } |
86 | $this->getRegex()->setLabel($label); |
87 | return $this; |
88 | } |
89 | |
90 | /** |
91 | * validate |
92 | * @param string $value |
93 | * @return bool |
94 | */ |
95 | public function testValue(mixed $value): bool |
96 | { |
97 | return $this->getRegex()->match($value); |
98 | } |
99 | } |