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