Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Accepted | |
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 | * Accepted 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 Accepted extends AbstractValidator |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * Method to evaluate the validator |
| 31 | * |
| 32 | * @param mixed $input |
| 33 | * @return bool |
| 34 | */ |
| 35 | public function evaluate(mixed $input = null): bool |
| 36 | { |
| 37 | // Set the input, if passed |
| 38 | if ($input !== null) { |
| 39 | $this->input = $input; |
| 40 | } |
| 41 | |
| 42 | if (is_string($this->input)) { |
| 43 | $this->input = strtolower($this->input); |
| 44 | } |
| 45 | |
| 46 | // Set the default message |
| 47 | if (!$this->hasMessage()) { |
| 48 | $this->generateDefaultMessage(); |
| 49 | } |
| 50 | |
| 51 | return in_array($this->input, [1, '1', true, 'true', 'yes'], true); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Generate default message |
| 56 | |
| 57 | * @param mixed $name |
| 58 | * @param mixed $value |
| 59 | * @return string |
| 60 | */ |
| 61 | public function generateDefaultMessage(mixed $name = null, mixed $value = null): string |
| 62 | { |
| 63 | $this->message = "The " . (($name !== null) ? "'" . $name . "'" : "value") . |
| 64 | " must a value of either 'yes', '1', 1, 'true' or true."; |
| 65 | |
| 66 | return $this->message; |
| 67 | } |
| 68 | |
| 69 | } |