DateTimeFactory::dateTimeFromDateString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
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