Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| NotStartsWith | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| evaluate | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| generateDefaultMessage | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Validator; |
| 16 | |
| 17 | /** |
| 18 | * Not starts with validator class |
| 19 | * |
| 20 | * @category Pop |
| 21 | * @package Pop\Validator |
| 22 | * @author Nick Sagona, III <nick@popphp.org> |
| 23 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 24 | * @license https://www.popphp.org/license New BSD License |
| 25 | * @version 5.0.0 |
| 26 | */ |
| 27 | class NotStartsWith extends AbstractValidator |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * Traits |
| 32 | */ |
| 33 | use ValueComparisonTrait; |
| 34 | |
| 35 | /** |
| 36 | * Method to evaluate the validator |
| 37 | * |
| 38 | * @param mixed $input |
| 39 | * @return bool |
| 40 | */ |
| 41 | public function evaluate(mixed $input = null): bool |
| 42 | { |
| 43 | // Set the input, if passed |
| 44 | if ($input !== null) { |
| 45 | $this->input = $input; |
| 46 | } |
| 47 | |
| 48 | // Set the default message |
| 49 | if (!$this->hasMessage()) { |
| 50 | $this->generateDefaultMessage(); |
| 51 | } |
| 52 | |
| 53 | return !$this->startsWithMatch($this->resolveInputValue(), $this->value); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Generate default message |
| 58 | |
| 59 | * @param mixed $name |
| 60 | * @param mixed $value |
| 61 | * @return string |
| 62 | */ |
| 63 | public function generateDefaultMessage(mixed $name = null, mixed $value = null): string |
| 64 | { |
| 65 | $valueString = $this->resolveComparisonValueString($value); |
| 66 | $this->message = "The " . (($name !== null) ? "'" . $name . "'" : "input") . |
| 67 | " must not start with '" . $valueString . "'."; |
| 68 | |
| 69 | return $this->message; |
| 70 | } |
| 71 | |
| 72 | } |