Conditions | 3 |
Paths | 4 |
Total Lines | 10 |
Lines | 10 |
Ratio | 100 % |
Changes | 0 |
1 | <?php |
||
23 | View Code Duplication | public static function createImmutable($init = null): DateTimeImmutable { |
|
24 | try { |
||
25 | if($init instanceof DateTimeInterface) { |
||
26 | return new DateTimeImmutable($init->format('c')); |
||
27 | } |
||
28 | return new DateTimeImmutable($init); |
||
29 | } catch (Exception $e) { |
||
30 | throw new RuntimeException($e->getMessage(), $e->getCode(), $e); |
||
31 | } |
||
32 | } |
||
33 | |||
48 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.