Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
AbstractValidator | |
100.00% |
12 / 12 |
|
100.00% |
7 / 7 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getMessage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getInput | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setValue | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setMessage | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setInput | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
evaluate | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Validator; |
15 | |
16 | /** |
17 | * Validator class |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Validator |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 4.0.0 |
25 | */ |
26 | abstract class AbstractValidator implements ValidatorInterface |
27 | { |
28 | |
29 | /** |
30 | * Validator value to test against |
31 | * @var mixed |
32 | */ |
33 | protected mixed $value = null; |
34 | |
35 | /** |
36 | * Input value to test |
37 | * @var mixed |
38 | */ |
39 | protected mixed $input = null; |
40 | |
41 | /** |
42 | * Validator message |
43 | * @var ?string |
44 | */ |
45 | protected ?string $message = null; |
46 | |
47 | /** |
48 | * Constructor |
49 | * |
50 | * Instantiate the validator object |
51 | * |
52 | * @param mixed $value |
53 | * @param ?string $message |
54 | */ |
55 | public function __construct(mixed $value = null, ?string $message = null) |
56 | { |
57 | $this->setValue($value); |
58 | if ($message !== null) { |
59 | $this->setMessage($message); |
60 | } |
61 | } |
62 | |
63 | /** |
64 | * Get the validator value |
65 | * |
66 | * @return mixed |
67 | */ |
68 | public function getValue(): mixed |
69 | { |
70 | return $this->value; |
71 | } |
72 | |
73 | /** |
74 | * Get the validator default message |
75 | * |
76 | * @return string|null |
77 | */ |
78 | public function getMessage(): string|null |
79 | { |
80 | return $this->message; |
81 | } |
82 | |
83 | /** |
84 | * GEt the validator input |
85 | * |
86 | * @return mixed |
87 | */ |
88 | public function getInput(): mixed |
89 | { |
90 | return $this->input; |
91 | } |
92 | |
93 | /** |
94 | * Set the validator value |
95 | * |
96 | * @param mixed $value |
97 | * @return AbstractValidator |
98 | */ |
99 | public function setValue(mixed $value): AbstractValidator |
100 | { |
101 | $this->value = $value; |
102 | return $this; |
103 | } |
104 | |
105 | /** |
106 | * Set the validator condition |
107 | * |
108 | * @param ?string $message |
109 | * @return AbstractValidator |
110 | */ |
111 | public function setMessage(?string $message = null): AbstractValidator |
112 | { |
113 | $this->message = $message; |
114 | return $this; |
115 | } |
116 | |
117 | /** |
118 | * Set the validator input |
119 | * |
120 | * @param mixed $input |
121 | * @return AbstractValidator |
122 | */ |
123 | public function setInput(mixed $input = null): AbstractValidator |
124 | { |
125 | $this->input = $input; |
126 | return $this; |
127 | } |
128 | |
129 | /** |
130 | * Evaluate |
131 | |
132 | * @param mixed $input |
133 | * @return bool |
134 | */ |
135 | abstract public function evaluate(mixed $input = null): bool; |
136 | |
137 | } |