Group   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 267
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 19
c 3
b 1
f 0
lcom 1
cbo 3
dl 0
loc 267
rs 10

17 Methods

Rating   Name   Duplication   Size   Complexity  
A getRoleName() 0 4 1
A setRoleName() 0 4 1
A getPublicName() 0 4 1
A setPublicName() 0 4 1
A isEssential() 0 4 1
A canBeEmpty() 0 4 1
A getFrontendUserCategory() 0 4 1
A setFrontendUserCategory() 0 4 1
A getFrontendModCategory() 0 4 1
A setFrontendModCategory() 0 4 1
A getACPCategory() 0 4 1
A setACPCategory() 0 4 1
A getUsers() 0 4 1
A setUsers() 0 4 1
A __construct() 0 21 1
A addUser() 0 6 2
A removeUser() 0 6 2
1
<?php
2
3
/*
4
 * (c) Jim Martens <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace TwoMartens\Bundle\CoreBundle\Model;
11
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\Common\Collections\Collection;
14
use FOS\UserBundle\Model\Group as FOSGroup;
15
16
/**
17
 * Represents a group.
18
 *
19
 * @author    Jim Martens <[email protected]>
20
 * @copyright 2013-2015 Jim Martens
21
 */
22
class Group extends FOSGroup
23
{
24
    /**
25
     * the role compatible name
26
     * @var string
27
     */
28
    protected $roleName;
29
30
    /**
31
     * the public name of the group
32
     * @var string
33
     */
34
    protected $name;
35
36
    /**
37
     * True, if this group is essential
38
     * @var bool
39
     */
40
    protected $isEssential;
41
42
    /**
43
     * True, if the group can have zero users.
44
     * @var bool
45
     */
46
    protected $canBeEmpty;
47
48
    /**
49
     * the option category for frontend user options
50
     * @var OptionCategory
51
     */
52
    protected $frontendUserCategory;
53
54
    /**
55
     * the option category for frontend mod options
56
     * @var OptionCategory
57
     */
58
    protected $frontendModCategory;
59
60
    /**
61
     * the option category for ACP options
62
     * @var OptionCategory
63
     */
64
    protected $acpCategory;
65
66
    /**
67
     * the list of users
68
     * @var Collection
69
     */
70
    protected $users;
71
72
    /**
73
     * Initializes the Group object.
74
     *
75
     * @param int            $id                   the ID
76
     * @param string         $roleName             only letters and underscore
77
     * @param string         $publicName           publicly visible name
78
     * @param bool           $isEssential          true, if the group is essential
79
     * @param bool           $canBeEmpty           true, if the group may be empty
80
     * @param string[]       $roles                array of roles granted by this group
81
     * @param OptionCategory $frontendUserCategory the frontend user category
82
     * @param OptionCategory $frontendModCategory  the frontend mod category
83
     * @param OptionCategory $acpCategory          the ACP category
84
     */
85
    public function __construct(
86
        $id,
87
        $roleName,
88
        $publicName,
89
        $isEssential,
90
        $canBeEmpty,
91
        array $roles,
92
        OptionCategory $frontendUserCategory,
93
        OptionCategory $frontendModCategory,
94
        OptionCategory $acpCategory
95
    ) {
96
        parent::__construct($publicName, $roles);
97
        $this->id = $id;
98
        $this->roleName = strtoupper($roleName);
99
        $this->isEssential = $isEssential;
100
        $this->canBeEmpty = $canBeEmpty;
101
        $this->frontendUserCategory = $frontendUserCategory;
102
        $this->frontendModCategory = $frontendModCategory;
103
        $this->acpCategory = $acpCategory;
104
        $this->users = new ArrayCollection();
105
    }
106
107
    /**
108
     * Returns the role compatible name of the group.
109
     *
110
     * The role compatible name will be used for the group role.
111
     * For example the role name is ADMIN. The resulting group
112
     * role will be ROLE_ADMIN.
113
     *
114
     * @return string
115
     */
116
    public function getRoleName()
117
    {
118
        return $this->roleName;
119
    }
120
121
    /**
122
     * Sets the role name.
123
     *
124
     * The role name may only contain letters and underscores. It is
125
     * in upper case.
126
     *
127
     * @param string $roleName
128
     */
129
    public function setRoleName($roleName)
130
    {
131
        $this->roleName = strtoupper($roleName);
132
    }
133
134
    /**
135
     * Returns the public name.
136
     *
137
     * The public name is the visible name of the group. This can also
138
     * be an identifier, which is translated to its representation.
139
     *
140
     * @return string
141
     */
142
    public function getPublicName()
143
    {
144
        return $this->name;
145
    }
146
147
    /**
148
     * Sets the public name.
149
     *
150
     * @param string $name
151
     */
152
    public function setPublicName($name)
153
    {
154
        $this->name = $name;
155
    }
156
157
    /**
158
     * Returns true, if the group is essential.
159
     *
160
     * An essential group is required for the functionality
161
     * of the web platform and cannot be deleted.
162
     *
163
     * @return bool
164
     */
165
    public function isEssential()
166
    {
167
        return $this->isEssential;
168
    }
169
170
    /**
171
     * Returns true, if the group can be empty.
172
     *
173
     * If a group MUST not be empty, the last user of it cannot
174
     * leave it (via whatever way). This is useful for admin
175
     * groups, since the admin should not be able to exclude
176
     * himself from the ACP.
177
     *
178
     * @return bool
179
     */
180
    public function canBeEmpty()
181
    {
182
        return $this->canBeEmpty;
183
    }
184
185
    /**
186
     * Returns the frontend user category.
187
     *
188
     * @return OptionCategory
189
     */
190
    public function getFrontendUserCategory()
191
    {
192
        return $this->frontendUserCategory;
193
    }
194
195
    /**
196
     * Sets the frontend user category.
197
     *
198
     * @param OptionCategory $category
199
     */
200
    public function setFrontendUserCategory(OptionCategory $category)
201
    {
202
        $this->frontendUserCategory = $category;
203
    }
204
205
    /**
206
     * Returns the frontend mod category.
207
     *
208
     * @return OptionCategory
209
     */
210
    public function getFrontendModCategory()
211
    {
212
        return $this->frontendModCategory;
213
    }
214
215
    /**
216
     * Sets the frontend mod category.
217
     *
218
     * @param OptionCategory $category
219
     */
220
    public function setFrontendModCategory(OptionCategory $category)
221
    {
222
        $this->frontendModCategory = $category;
223
    }
224
225
    /**
226
     * Returns the ACP category.
227
     *
228
     * @return OptionCategory
229
     */
230
    public function getACPCategory()
231
    {
232
        return $this->acpCategory;
233
    }
234
235
    /**
236
     * Sets the ACP category.
237
     *
238
     * @param OptionCategory $category
239
     */
240
    public function setACPCategory(OptionCategory $category)
241
    {
242
        $this->acpCategory = $category;
243
    }
244
245
    /**
246
     * Returns the users.
247
     *
248
     * @return Collection
249
     */
250
    public function getUsers()
251
    {
252
        return $this->users;
253
    }
254
255
    /**
256
     * Sets the users.
257
     *
258
     * @param Collection $users
259
     */
260
    public function setUsers(Collection $users)
261
    {
262
        $this->users = $users;
263
    }
264
265
    /**
266
     * Adds given user to group.
267
     *
268
     * @param User $user
269
     */
270
    public function addUser(User $user)
271
    {
272
        if (!$this->users->contains($user)) {
273
            $this->users->add($user);
274
        }
275
    }
276
277
    /**
278
     * Removes given user from group.
279
     *
280
     * @param User $user
281
     */
282
    public function removeUser(User $user)
283
    {
284
        if ($this->users->contains($user)) {
285
            $this->users->removeElement($user);
286
        }
287
    }
288
}
289