Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
CountGreaterThan | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
evaluate | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
generateDefaultMessage | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
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@noladev.com> |
7 | * @copyright Copyright (c) 2009-2025 NOLA Interactive, LLC. |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Validator; |
15 | |
16 | /** |
17 | * Count greater than validator class |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Validator |
21 | * @author Nick Sagona, III <dev@noladev.com> |
22 | * @copyright Copyright (c) 2009-2025 NOLA Interactive, LLC. |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 4.5.0 |
25 | */ |
26 | class CountGreaterThan 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 | // Set the input, if passed |
39 | if ($input !== null) { |
40 | $this->input = $input; |
41 | } |
42 | |
43 | // Set the default message |
44 | if (!$this->hasMessage()) { |
45 | $this->generateDefaultMessage(); |
46 | } |
47 | |
48 | if (!is_array($input)) { |
49 | throw new Exception('Error: The evaluated input must be an array.'); |
50 | } |
51 | |
52 | return (count($this->input) > $this->value); |
53 | } |
54 | |
55 | /** |
56 | * Generate default message |
57 | |
58 | * @param mixed $name |
59 | * @param mixed $value |
60 | * @return string |
61 | */ |
62 | public function generateDefaultMessage(mixed $name = null, mixed $value = null): string |
63 | { |
64 | $this->message = "The count of " . (($name !== null) ? "'" . $name . "'" : "the value") . |
65 | " must be greater than '" . ($value ?? $this->value) . "'."; |
66 | |
67 | return $this->message; |
68 | } |
69 | |
70 | } |