| Conditions | 5 |
| Paths | 5 |
| Total Lines | 19 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 33 | public static function toDatetime($date): \DateTime |
||
| 34 | { |
||
| 35 | if ($date === null) { |
||
| 36 | throw new \Exception('$date can\'t be null.'); |
||
| 37 | } |
||
| 38 | // DateTime |
||
| 39 | if ($date instanceof \DateTime) { |
||
| 40 | return $date; |
||
| 41 | } |
||
| 42 | // DateTimeImmutable |
||
| 43 | if ($date instanceof \DateTimeImmutable) { |
||
| 44 | return \DateTime::createFromImmutable($date); |
||
| 45 | } |
||
| 46 | // timestamp |
||
| 47 | if (\is_int($date)) { |
||
| 48 | return (new \DateTime())->setTimestamp($date); |
||
| 49 | } |
||
| 50 | |||
| 51 | return new \DateTime($date); |
||
| 52 | } |
||
| 68 |