Total Complexity | 6 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | trait DateTimeUpdatedTrait |
||
16 | { |
||
17 | /** |
||
18 | * @var DateTimeInterface |
||
19 | */ |
||
20 | private $updatedAt; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected static $updatedAtStringFormat = 'Y-m-d H:i:s'; |
||
26 | |||
27 | /** |
||
28 | * @return DateTimeInterface|null |
||
29 | */ |
||
30 | 8 | public function getUpdatedAt(): ?DateTimeInterface |
|
31 | { |
||
32 | 8 | return $this->updatedAt; |
|
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param string|null $format |
||
37 | * @return string|null |
||
38 | */ |
||
39 | 3 | public function getUpdatedAtString(?string $format = null): ?string |
|
40 | { |
||
41 | 3 | if (!$this->hasUpdatedAt()) { |
|
42 | 1 | return null; |
|
43 | } |
||
44 | |||
45 | return $this |
||
46 | 2 | ->getUpdatedAt() |
|
47 | 2 | ->format($format ?? self::$updatedAtStringFormat) |
|
48 | ; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return bool |
||
53 | */ |
||
54 | 5 | public function hasUpdatedAt(): bool |
|
55 | { |
||
56 | 5 | return $this->getUpdatedAt() instanceof DateTimeInterface; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param DateTimeInterface $updatedAt |
||
61 | * @return void |
||
62 | */ |
||
63 | 5 | public function setUpdatedAt(DateTimeInterface $updatedAt): void |
|
66 | 5 | } |
|
67 | |||
68 | /** |
||
69 | * @return void |
||
70 | * @throws Exception |
||
71 | */ |
||
72 | 1 | public function forgeUpdatedAt(): void |
|
76 | ); |
||
77 | 1 | } |
|
79 |