| Total Complexity | 7 |
| Total Lines | 73 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | trait HasExpiredAtHelpers |
||
| 19 | { |
||
| 20 | public function initializeHasExpiredAtHelpers(): void |
||
| 21 | { |
||
| 22 | $this->dates[] = 'expired_at'; |
||
|
|
|||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Set expired flag. |
||
| 27 | * |
||
| 28 | * @return static |
||
| 29 | */ |
||
| 30 | public function setExpiredFlag() |
||
| 31 | { |
||
| 32 | $this->setAttribute('expired_at', Carbon::now()); |
||
| 33 | |||
| 34 | return $this; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Unset expired flag. |
||
| 39 | * |
||
| 40 | * @return static |
||
| 41 | */ |
||
| 42 | public function unsetExpiredFlag() |
||
| 43 | { |
||
| 44 | $this->setAttribute('expired_at', null); |
||
| 45 | |||
| 46 | return $this; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * If entity is expired. |
||
| 51 | * |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | public function isExpired(): bool |
||
| 55 | { |
||
| 56 | return !is_null($this->getAttributeValue('expired_at')); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * If entity is opened. |
||
| 61 | * |
||
| 62 | * @return bool |
||
| 63 | */ |
||
| 64 | public function isUnexpired(): bool |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Mark entity as expired. |
||
| 71 | * |
||
| 72 | * @return void |
||
| 73 | */ |
||
| 74 | public function expire(): void |
||
| 75 | { |
||
| 76 | $this->setExpiredFlag()->save(); |
||
| 77 | |||
| 78 | $this->fireModelEvent('expired', false); |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Mark entity as opened. |
||
| 83 | * |
||
| 84 | * @return void |
||
| 85 | */ |
||
| 86 | public function unexpire(): void |
||
| 91 | } |
||
| 92 | } |
||
| 93 |