Total Complexity | 8 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
12 | abstract class DateFormatValueObject implements DateFormatValueObjectInterface |
||
13 | { |
||
14 | private $value; |
||
15 | |||
16 | private $format; |
||
17 | |||
18 | /** |
||
19 | * @throws Exception if value is invalid |
||
20 | */ |
||
21 | public function __construct(?DateTimeImmutable $value, string $format = DateTime::ATOM) |
||
22 | { |
||
23 | $this->guard($value, $format); |
||
24 | $this->value = $value; |
||
25 | $this->format = $format; |
||
26 | } |
||
27 | |||
28 | public function equals(DateFormatValueObjectInterface $other): bool |
||
44 | } |
||
45 | |||
46 | public function getValue(): ?string |
||
47 | { |
||
48 | if ($this->value === null) { |
||
49 | return null; |
||
50 | } |
||
51 | return $this->value->format($this->format); |
||
52 | } |
||
53 | |||
54 | public function getDateTime(): ?DateTimeImmutable |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @throws Exception if value is invalid |
||
61 | */ |
||
62 | abstract protected function guard(?DateTimeImmutable $value, string $format): void; |
||
63 | } |
||
64 |