Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
LengthBetweenInclude | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
6 | |
100.00% |
1 / 1 |
evaluate | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
6 |
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 | * Length between/include 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 | class LengthBetweenInclude extends AbstractValidator |
27 | { |
28 | |
29 | /** |
30 | * Method to evaluate the validator |
31 | * |
32 | * @param mixed $input |
33 | * @throws Exception |
34 | * @return bool |
35 | */ |
36 | public function evaluate(mixed $input = null): bool |
37 | { |
38 | if (!is_array($this->value)) { |
39 | throw new Exception('The value must be an array.'); |
40 | } else if (count($this->value) != 2) { |
41 | throw new Exception('The value must be an array that contains 2 values.'); |
42 | } |
43 | |
44 | // Set the input, if passed |
45 | if ($input !== null) { |
46 | $this->input = $input; |
47 | } |
48 | |
49 | // Set the default message |
50 | if ($this->message === null) { |
51 | $this->message = 'The value length must be between or equal to ' . $this->value[0] . ' and ' . $this->value[1] . '.'; |
52 | } |
53 | |
54 | return ((strlen((string)$this->input) >= $this->value[0]) && (strlen((string)$this->input) <= $this->value[1])); |
55 | } |
56 | |
57 | } |