Conditions | 5 |
Paths | 4 |
Total Lines | 18 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
19 | 63 | public function normalize(mixed $options, mixed $value): string |
|
20 | { |
||
21 | // param is used for nullable |
||
22 | 63 | if ($this->nullable && empty($value)) { |
|
23 | 8 | return ''; |
|
24 | } |
||
25 | |||
26 | 63 | if ($value instanceof \DateTimeInterface) { |
|
27 | 13 | return $value->format($this->getFormat()); |
|
28 | } |
||
29 | |||
30 | 55 | $time = \strtotime(\strval($value)); |
|
31 | |||
32 | 55 | if (!$time) { |
|
33 | 1 | throw new \DomainException('Not a valid date: ' . $value); |
|
34 | } |
||
35 | |||
36 | 54 | return \date($this->getFormat(), $time); |
|
37 | } |
||
39 |