Total Complexity | 9 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | class TestClock implements Clock |
||
14 | { |
||
15 | /** |
||
16 | * @private |
||
17 | */ |
||
18 | const FORMAT_OF_TIME = 'Y-m-d H:i:s.uO'; |
||
19 | |||
20 | /** |
||
21 | * @var DateTimeImmutable |
||
22 | */ |
||
23 | private $time; |
||
24 | |||
25 | /** |
||
26 | * @var DateTimeZone |
||
27 | */ |
||
28 | private $timeZone; |
||
29 | |||
30 | 26 | public function __construct(DateTimeZone $timeZone = null) |
|
31 | { |
||
32 | 26 | $this->timeZone = $timeZone ?: new DateTimeZone('UTC'); |
|
33 | 26 | $this->tick(); |
|
34 | 26 | } |
|
35 | |||
36 | 26 | public function tick(): void |
|
37 | { |
||
38 | 26 | $this->time = new DateTimeImmutable('now', $this->timeZone); |
|
39 | 26 | } |
|
40 | |||
41 | 3 | public function fixate(string $input): void |
|
42 | { |
||
43 | 3 | $preciseTime = sprintf('%s.000000', $input); |
|
44 | 3 | $dateTime = DateTimeImmutable::createFromFormat('Y-m-d H:i:s.u', $preciseTime, $this->timeZone); |
|
45 | |||
46 | 3 | if ( ! $dateTime instanceof DateTimeImmutable) { |
|
47 | 1 | throw new InvalidArgumentException("Invalid input for date/time fixation provided: {$input}"); |
|
48 | } |
||
49 | |||
50 | 2 | $this->time = $dateTime; |
|
51 | 2 | } |
|
52 | |||
53 | 1 | public function moveForward(DateInterval $interval): void |
|
54 | { |
||
55 | 1 | $this->time = $this->dateTime()->add($interval); |
|
56 | 1 | } |
|
57 | |||
58 | 9 | public function dateTime(): DateTimeImmutable |
|
59 | { |
||
60 | 9 | return $this->time; |
|
61 | } |
||
62 | |||
63 | 5 | public function pointInTime(): PointInTime |
|
66 | } |
||
67 | |||
68 | 1 | public function timeZone(): DateTimeZone |
|
69 | { |
||
71 | } |
||
72 | } |
||
73 |