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

TestClock   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A tick() 0 4 1
A fixate() 0 5 1
A dateTime() 0 4 1
A pointInTime() 0 4 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
}