Total Complexity | 6 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
12 | abstract class TimestampValueObject implements TimestampValueObjectInterface |
||
13 | { |
||
14 | private $value; |
||
15 | |||
16 | /** |
||
17 | * @throws Exception if value is invalid |
||
18 | */ |
||
19 | public function __construct(DateTimeImmutable $value) |
||
20 | { |
||
21 | try { |
||
22 | $this->guard($value); |
||
23 | } catch (Throwable $e) { |
||
24 | throw $this->throwException($value, $e); |
||
25 | } |
||
26 | $this->value = $value; |
||
27 | } |
||
28 | |||
29 | public function getDateTime(): DateTimeImmutable |
||
32 | } |
||
33 | |||
34 | public function equals(TimestampValueObjectInterface $other): bool |
||
35 | { |
||
36 | if (static::class !== get_class($other)) { |
||
37 | return false; |
||
38 | } |
||
39 | return $this->getValue() === $other->getValue(); |
||
40 | } |
||
41 | |||
42 | public function getValue(): int |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @throws Throwable if value is invalid |
||
49 | */ |
||
50 | abstract protected function guard(DateTimeImmutable $value): void; |
||
51 | |||
52 | abstract protected function throwException(DateTimeImmutable $value, Throwable $e): Exception; |
||
53 | } |
||
54 |