DateTime   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 20
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A createFromMultipleFormats() 0 18 6
1
<?php
2
3
namespace IproSync\Ipro;
4
5
use Carbon\Carbon;
6
use Carbon\Exceptions\InvalidFormatException;
7
8
class DateTime
9
{
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
    }
29
}
30