DateField   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 26
rs 10
c 0
b 0
f 0
ccs 11
cts 11
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDateTime() 0 7 2
A __construct() 0 5 1
A getDateTime() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Artack\Dsn\Field;
6
7
class DateField extends AbstractField
8
{
9
    private $dateTime;
10
11 8
    public function __construct(string $name, \DateTimeInterface $date)
12
    {
13 8
        parent::__construct($name, null);
14
15 8
        $this->setDateTime($date);
16 8
    }
17
18 6
    public function getDateTime(): \DateTimeImmutable
19
    {
20 6
        return $this->dateTime;
21
    }
22
23
    /**
24
     * If a DateTime instance is provided, it is converted to DateTimeImmutable.
25
     */
26 8
    public function setDateTime(\DateTimeInterface $dateTime): void
27
    {
28 8
        if ($dateTime instanceof \DateTime) {
29 2
            $immutable = new \DateTimeImmutable('@'.$dateTime->getTimestamp());
30 2
            $dateTime = $immutable->setTimezone($dateTime->getTimezone());
31
        }
32 8
        $this->dateTime = $dateTime;
33 8
    }
34
}
35