Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.86% covered (success)
92.86%
13 / 14
50.00% covered (warning)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GreaterThanEqual
92.86% covered (success)
92.86%
13 / 14
50.00% covered (warning)
50.00%
1 / 2
9.03
0.00% covered (danger)
0.00%
0 / 1
 evaluate
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 generateDefaultMessage
87.50% covered (success)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
5.05
1<?php
2declare(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 */
15namespace Pop\Validator;
16
17/**
18 * Greater than or equal 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 */
27class GreaterThanEqual extends AbstractValidator
28{
29
30    /**
31     * Method to evaluate the validator
32     *
33     * @param  mixed $input
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        $inputValue = ($this->hasKeyField()) ? $this->getKeyFieldValue() : $this->input;
49
50        return ($inputValue >= $this->value);
51    }
52
53    /**
54     * Generate default message
55
56     * @param  mixed $name
57     * @param  mixed $value
58     * @return string
59     */
60    public function generateDefaultMessage(mixed $name = null, mixed $value = null): string
61    {
62        if ($value !== null) {
63            $valueString = $value;
64        } else if (!empty($this->value) && !is_array($this->value)) {
65            $valueString = $this->value;
66        } else {
67            $valueString = 'the value.';
68        }
69        $this->message = "The " . (($name !== null) ? "'" . $name . "'" : "input") .
70            " must be greater than or equal to '" . $valueString . "'.";
71
72        return $this->message;
73    }
74
75}