DateTimeFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A dateTimeFromDateString() 0 16 2
1
<?php
2
/**
3
 * @file
4
 */
5
6
namespace CultuurNet\UDB3\Cdb;
7
8
class DateTimeFactory
9
{
10
    /**
11
     * @param string $dateString
12
     * @return \DateTimeImmutable
13
     * @throws \InvalidArgumentException
14
     */
15
    public static function dateTimeFromDateString($dateString)
16
    {
17
        $date = \DateTimeImmutable::createFromFormat(
18
            'Y-m-d?H:i:s',
19
            $dateString,
20
            new \DateTimeZone('Europe/Brussels')
21
        );
22
23
        if (!$date instanceof \DateTimeImmutable) {
24
            throw new \InvalidArgumentException(
25
                'Value of argument $dateString is not convertable to a DateTimeImmutable object'
26
            );
27
        }
28
29
        return $date;
30
    }
31
}
32