Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
DateTimeTrait | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
10 | |
100.00% |
1 / 1 |
getValue | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
setValue | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
evaluate | |
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@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 | use Pop\Utils; |
17 | |
18 | /** |
19 | * Date-time greater than validator class |
20 | * |
21 | * @category Pop |
22 | * @package Pop\Validator |
23 | * @author Nick Sagona, III <dev@nolainteractive.com> |
24 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
25 | * @license http://www.popphp.org/license New BSD License |
26 | * @version 4.0.0 |
27 | */ |
28 | trait DateTimeTrait |
29 | { |
30 | |
31 | use Utils\DateTimeTrait; |
32 | |
33 | /** |
34 | * Get the validator value |
35 | * |
36 | * @return mixed |
37 | */ |
38 | public function getValue(): mixed |
39 | { |
40 | if (!empty($this->dateTimeFormat)) { |
41 | if (is_array($this->value)) { |
42 | $values = $this->value; |
43 | foreach ($values as $key => $value) { |
44 | $values[$key] = date($this->dateTimeFormat, $value); |
45 | } |
46 | return $values; |
47 | } else { |
48 | return date($this->dateTimeFormat, $this->value); |
49 | } |
50 | } else { |
51 | return $this->value; |
52 | } |
53 | } |
54 | |
55 | /** |
56 | * Set the validator value |
57 | * |
58 | * @param mixed $value |
59 | * @return static |
60 | */ |
61 | public function setValue(mixed $value): static |
62 | { |
63 | if ($value !== null) { |
64 | if (is_array($value)) { |
65 | $this->detectFormat($value[0]); |
66 | $value = array_map('strtotime', $value); |
67 | } else { |
68 | $this->detectFormat($value); |
69 | if ($this->dateTimeFormat !== null) { |
70 | $value = strtotime($value); |
71 | } |
72 | } |
73 | } |
74 | return parent::setValue($value); |
75 | } |
76 | |
77 | /** |
78 | * Method to evaluate the validator |
79 | * |
80 | * @param mixed $input |
81 | * @return bool |
82 | */ |
83 | public function evaluate(mixed $input = null): bool |
84 | { |
85 | if ($input !== null) { |
86 | $input = strtotime($input); |
87 | } |
88 | return parent::evaluate($input); |
89 | } |
90 | |
91 | } |