Conditions | 6 |
Paths | 6 |
Total Lines | 18 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 42 |
Changes | 0 |
1 | <?php |
||
10 | public static function createFromMultipleFormats(array $formats, string $dateString): Carbon |
||
11 | { |
||
12 | $dateObj = null; |
||
13 | $lastError = null; |
||
14 | foreach ($formats as $format) { |
||
15 | try { |
||
16 | if ($dateObj = Carbon::createFromFormat($format, $dateString)) { |
||
17 | break; |
||
18 | } |
||
19 | } catch (InvalidFormatException $e) { |
||
20 | $lastError = $e; |
||
21 | } |
||
22 | } |
||
23 | if (!$dateObj && $lastError) { |
||
24 | throw $lastError; |
||
25 | } |
||
26 | |||
27 | return $dateObj; |
||
28 | } |
||
30 |