Completed
Push — master ( 4803b3...959101 )
by Frank
03:46
created

TestClock::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace EventSauce\EventSourcing\Time;
4
5
use DateTimeImmutable;
6
use EventSauce\EventSourcing\PointInTime;
7
8
class TestClock implements Clock
9
{
10
    /**
11
     * @private
12
     */
13
    const FORMAT_OF_TIME = 'Y-m-d H:i:s.uO';
14
15
    private $time;
16
17 11
    final public function __construct()
18
    {
19 11
        $this->tick();
20 11
    }
21
22 11
    public function tick()
23
    {
24 11
        $this->time = DateTimeImmutable::createFromFormat('U.u', sprintf('%.6f', microtime(true)));
25 11
    }
26
27 1
    public function fixate(string $dateTime)
28
    {
29 1
        $preciseTime = sprintf('%s.000000+0000', $dateTime);
30 1
        $this->time = DateTimeImmutable::createFromFormat(self::FORMAT_OF_TIME, $preciseTime);
31 1
    }
32
33 7
    public function dateTime(): DateTimeImmutable
34
    {
35 7
        return $this->time;
36
    }
37
38 4
    public function pointInTime(): PointInTime
39
    {
40 4
        return PointInTime::fromDateTime($this->dateTime());
41
    }
42
}