Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Group | |
100.00% |
14 / 14 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setStatus | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
__toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toArray | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
jsonSerialize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\Account |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Account; |
16 | |
17 | use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; |
18 | |
19 | /** |
20 | * Account group class. |
21 | * |
22 | * @package phpOMS\Account |
23 | * @license OMS License 2.0 |
24 | * @link https://jingga.app |
25 | * @since 1.0.0 |
26 | */ |
27 | class Group implements \JsonSerializable |
28 | { |
29 | /** |
30 | * Group id. |
31 | * |
32 | * @var int |
33 | * @since 1.0.0 |
34 | */ |
35 | public int $id = 0; |
36 | |
37 | /** |
38 | * Group name. |
39 | * |
40 | * @var string |
41 | * @since 1.0.0 |
42 | */ |
43 | public string $name = ''; |
44 | |
45 | /** |
46 | * Group name. |
47 | * |
48 | * @var string |
49 | * @since 1.0.0 |
50 | */ |
51 | public string $description = ''; |
52 | |
53 | /** |
54 | * Group members. |
55 | * |
56 | * @var array |
57 | * @since 1.0.0 |
58 | */ |
59 | public array $members = []; |
60 | |
61 | /** |
62 | * Parents. |
63 | * |
64 | * @var int[] |
65 | * @since 1.0.0 |
66 | */ |
67 | public array $parents = []; |
68 | |
69 | /** |
70 | * Group status. |
71 | * |
72 | * @var int |
73 | * @since 1.0.0 |
74 | */ |
75 | public int $status = GroupStatus::INACTIVE; |
76 | |
77 | use PermissionHandlingTrait; |
78 | |
79 | /** |
80 | * Get group id. |
81 | * |
82 | * @return int Returns the id of the group |
83 | * |
84 | * @since 1.0.0 |
85 | */ |
86 | public function getId() : int |
87 | { |
88 | return $this->id; |
89 | } |
90 | |
91 | /** |
92 | * Get group status. |
93 | * |
94 | * @return int Group status |
95 | * |
96 | * @since 1.0.0 |
97 | */ |
98 | public function getStatus() : int |
99 | { |
100 | return $this->status; |
101 | } |
102 | |
103 | /** |
104 | * Set group status. |
105 | * |
106 | * @param int $status Group status |
107 | * |
108 | * @return void |
109 | * |
110 | * @throws InvalidEnumValue This exception is thrown if an invalid status is used |
111 | * |
112 | * @since 1.0.0 |
113 | */ |
114 | public function setStatus(int $status) : void |
115 | { |
116 | if (!GroupStatus::isValidValue($status)) { |
117 | throw new InvalidEnumValue($status); |
118 | } |
119 | |
120 | $this->status = $status; |
121 | } |
122 | |
123 | /** |
124 | * Get string representation. |
125 | * |
126 | * @return string Returns the json_encode of this object |
127 | * |
128 | * @since 1.0.0 |
129 | */ |
130 | public function __toString() : string |
131 | { |
132 | return (string) \json_encode($this->toArray()); |
133 | } |
134 | |
135 | /** |
136 | * {@inheritdoc} |
137 | */ |
138 | public function toArray() : array |
139 | { |
140 | return [ |
141 | 'id' => $this->id, |
142 | 'name' => $this->name, |
143 | 'description' => $this->description, |
144 | 'permissions' => $this->permissions, |
145 | 'members' => $this->members, |
146 | ]; |
147 | } |
148 | |
149 | /** |
150 | * Json serialize. |
151 | * |
152 | * @return array<string, mixed> |
153 | * |
154 | * @since 1.0.0 |
155 | */ |
156 | |
157 | /** |
158 | * {@inheritdoc} |
159 | */ |
160 | public function jsonSerialize() : mixed |
161 | { |
162 | return $this->toArray(); |
163 | } |
164 | } |