Completed
Push — master ( 22bf09...6ecd27 )
by Andreas
15s queued 10s
created

DateImmutableType   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 24
ccs 6
cts 10
cp 0.6
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDateTime() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Types;
6
7
use DateTime;
8
use DateTimeImmutable;
9
use DateTimeInterface;
10
use RuntimeException;
11
use function get_class;
12
use function sprintf;
13
14
class DateImmutableType extends DateType
15
{
16
    /**
17
     * @return DateTimeImmutable
18
     */
19 19
    public static function getDateTime($value) : DateTimeInterface
20
    {
21 19
        $datetime = parent::getDateTime($value);
22
23 14
        if ($datetime instanceof DateTimeImmutable) {
24 4
            return $datetime;
25
        }
26
27 12
        if ($datetime instanceof DateTime) {
28 12
            return DateTimeImmutable::createFromMutable($datetime);
29
        }
30
31
        throw new RuntimeException(sprintf(
32
            '%s::getDateTime has returned an unsupported implementation of DateTimeInterface: %s',
33
            parent::class,
34
            get_class($datetime)
35
        ));
36
    }
37
}
38