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