Completed
Push — master ( 8aac39...2d67c2 )
by Frank
02:30
created

SystemClock::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace EventSauce\EventSourcing\Time;
4
5
use DateTimeImmutable;
6
use DateTimeZone;
7
use EventSauce\EventSourcing\PointInTime;
8
9
class SystemClock implements Clock
10
{
11
    /**
12
     * @var DateTimeZone
13
     */
14
    private $timeZone;
15
16 2
    public function __construct(DateTimeZone $timeZone = null)
17
    {
18 2
        $this->timeZone = $timeZone ?: new DateTimeZone('UTC');
19 2
    }
20
21 2
    public function dateTime(): DateTimeImmutable
22
    {
23 2
        return new DateTimeImmutable('now', $this->timeZone);
24
    }
25
26 1
    public function pointInTime(): PointInTime
27
    {
28 1
        return PointInTime::fromDateTime($this->dateTime());
29
    }
30
}