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