Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ComparesDateTime | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
validate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
toDateTime | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Http\Validation\Rules; |
6 | |
7 | use Engelsystem\Helpers\Carbon; |
8 | |
9 | trait ComparesDateTime |
10 | { |
11 | use Truthy; |
12 | |
13 | protected mixed $compareTo; |
14 | protected bool $orEqual; |
15 | |
16 | public function __construct(mixed $compareTo, mixed $orEqual = false) |
17 | { |
18 | $this->orEqual = $this->truthy($orEqual); |
19 | $this->compareTo = $this->toDateTime($compareTo); |
20 | } |
21 | |
22 | public function validate(mixed $input): bool |
23 | { |
24 | $input = $this->toDateTime($input); |
25 | |
26 | return $this->compare($input); |
27 | } |
28 | |
29 | protected function toDateTime(mixed $value): mixed |
30 | { |
31 | if (is_string($value)) { |
32 | $value = Carbon::make($value); |
33 | } |
34 | |
35 | return $value; |
36 | } |
37 | } |