Completed
Push — feature/moveCommonLogicToTrait ( df8bcc...95b46c )
by Andreas
07:29
created

DateTimeImmutable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 2

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 2
cbo 2
dl 0
loc 30
ccs 4
cts 6
cp 0.6667
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDateTime() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Copyright Andrea Heigl <[email protected]>
7
 *
8
 * Licenses under the MIT-license. For details see the included file LICENSE.md
9
 */
10
11
namespace UTCDateTime;
12
13
use \DateTimeImmutable as DefaultDateTimeImmutable;
14
use \DateTimeZone;
15
16
class DateTimeImmutable extends DefaultDateTimeImmutable
17
{
18
    const RFC7231 = 'D, d M Y H:i:s \G\M\T';
19
20
    const PDF = 'YmdHis\Z';
21
22
    use DateTimeBase;
23
24
    /**
25
     * @param string       $time
26
     * @param DateTimeZone $timezone
27
     *
28
     * @return void
29
     */
30 7
    public function __construct($time = 'now', DateTimeZone $timezone = null)
31
    {
32 7
        $utcdate = new DateTime($time, $timezone);
33 7
        parent::__construct($utcdate->format('Y-m-d H:i:s'), new DateTimeZone('UTC'));
34 7
    }
35
36
    /**
37
     * Get a PHP-DateTime-Object from this class for further handling
38
     *
39
     * @return self
40
     */
41
    public function getDateTime()
42
    {
43
        return new static($this->format('Y-m-d H:i:s'), new DateTimeZone('UTC'));
44
    }
45
}
46