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