Conditions | 6 |
Paths | 5 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
56 | public static function create($datepoint): DateTimeImmutable |
||
57 | { |
||
58 | if ($datepoint instanceof DateTimeImmutable) { |
||
59 | return $datepoint; |
||
60 | } |
||
61 | |||
62 | if ($datepoint instanceof DateTime) { |
||
63 | return DateTimeImmutable::createFromMutable($datepoint); |
||
64 | } |
||
65 | |||
66 | if (false !== ($timestamp = filter_var($datepoint, FILTER_VALIDATE_INT))) { |
||
67 | return new DateTimeImmutable('@'.$timestamp); |
||
68 | } |
||
69 | |||
70 | if (is_string($datepoint)) { |
||
71 | return new DateTimeImmutable($datepoint); |
||
72 | } |
||
73 | |||
74 | throw new TypeError(sprintf( |
||
75 | 'The datepoint must be expressed using an integer, a string or a DateTimeInterface object %s given', |
||
76 | is_object($datepoint) ? get_class($datepoint) : gettype($datepoint) |
||
77 | )); |
||
80 |