Total Complexity | 7 |
Total Lines | 73 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
16 | trait HasEndedFlagHelpers |
||
17 | { |
||
18 | public function initializeHasEndedFlagHelpers(): void |
||
19 | { |
||
20 | $this->casts['is_ended'] = 'boolean'; |
||
|
|||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Set ended flag. |
||
25 | * |
||
26 | * @return static |
||
27 | */ |
||
28 | public function setEndedFlag() |
||
29 | { |
||
30 | $this->setAttribute('is_ended', true); |
||
31 | |||
32 | return $this; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Unset ended flag. |
||
37 | * |
||
38 | * @return static |
||
39 | */ |
||
40 | public function unsetEndedFlag() |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * If entity is ended. |
||
49 | * |
||
50 | * @return bool |
||
51 | */ |
||
52 | public function isEnded(): bool |
||
53 | { |
||
54 | return $this->getAttributeValue('is_ended'); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * If entity is opened. |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function isUnended(): bool |
||
63 | { |
||
64 | return !$this->isEnded(); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Mark entity as ended. |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | public function end(): void |
||
73 | { |
||
74 | $this->setEndedFlag()->save(); |
||
75 | |||
76 | $this->fireModelEvent('ended', false); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Mark entity as opened. |
||
81 | * |
||
82 | * @return void |
||
83 | */ |
||
84 | public function unend(): void |
||
89 | } |
||
90 | } |
||
91 |