Total Complexity | 6 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | final class FrozenClock implements ClockInterface |
||
25 | { |
||
26 | 5 | public function __construct(private DateTimeImmutable $now) {} |
|
27 | |||
28 | /** |
||
29 | * @inheritDoc |
||
30 | */ |
||
31 | 1 | public function __toString(): string |
|
37 | 1 | ); |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * Adjusts the FrozenClock time based on a given modifier. |
||
42 | * |
||
43 | * @see https://www.php.net/manual/en/datetime.formats.php |
||
44 | * @see https://www.php.net/manual/en/class.datemalformedstringexception.php |
||
45 | * |
||
46 | * @psalm-suppress PossiblyFalsePropertyAssignmentValue |
||
47 | */ |
||
48 | 1 | public function adjustTo(string $withModifier): void |
|
49 | { |
||
50 | 1 | $this->now = $this->now->modify($withModifier); |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * @inheritDoc |
||
55 | */ |
||
56 | 5 | public function now(): DateTimeImmutable |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * Sets the FrozenClock to a specific time. |
||
63 | */ |
||
64 | 1 | public function setTo(DateTimeImmutable $now): void |
|
65 | { |
||
66 | 1 | $this->now = $now; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * @inheritDoc |
||
71 | * |
||
72 | * @throws \DateMalformedStringException |
||
73 | */ |
||
74 | 2 | public static function fromUtc(): FrozenClock |
|
78 | 2 | ); |
|
79 | } |
||
81 |