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