| Conditions | 6 |
| Paths | 6 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 6 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | 2 | public static function createFromMultipleFormats(array $formats, string $dateString): Carbon |
|
| 19 | { |
||
| 20 | 2 | $dateObj = null; |
|
| 21 | 2 | $lastError = null; |
|
| 22 | 2 | foreach ($formats as $format) { |
|
| 23 | try { |
||
| 24 | 2 | if ($dateObj = Carbon::createFromFormat($format, $dateString)) { |
|
| 25 | 1 | break; |
|
| 26 | } |
||
| 27 | 2 | } catch (InvalidFormatException $e) { |
|
| 28 | 2 | $lastError = $e; |
|
| 29 | } |
||
| 30 | } |
||
| 31 | 2 | if (!$dateObj && $lastError) { |
|
| 32 | 1 | throw $lastError; |
|
| 33 | } |
||
| 34 | |||
| 35 | 1 | return $dateObj; |
|
| 36 | } |
||
| 38 |