These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Sylius package. |
||
5 | * |
||
6 | * (c) Paweł Jędrzejewski |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Sylius\Component\Rbac\Model; |
||
13 | |||
14 | use Doctrine\Common\Collections\ArrayCollection; |
||
15 | use Doctrine\Common\Collections\Collection; |
||
16 | use Sylius\Component\Resource\Model\TimestampableTrait; |
||
17 | |||
18 | /** |
||
19 | * Default role implementation. |
||
20 | * |
||
21 | * @author Paweł Jędrzejewski <[email protected]> |
||
22 | */ |
||
23 | class Role implements RoleInterface |
||
24 | { |
||
25 | use TimestampableTrait; |
||
26 | |||
27 | /** |
||
28 | * @var mixed |
||
29 | */ |
||
30 | protected $id; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $code; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $name; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $description; |
||
46 | |||
47 | /** |
||
48 | * @var null|RoleInterface |
||
49 | */ |
||
50 | protected $parent; |
||
51 | |||
52 | /** |
||
53 | * @var Collection|RoleInterface[] |
||
54 | */ |
||
55 | protected $children; |
||
56 | |||
57 | /** |
||
58 | * Required by DoctrineExtensions. |
||
59 | * |
||
60 | * @var int |
||
61 | */ |
||
62 | protected $left; |
||
63 | |||
64 | /** |
||
65 | * Required by DoctrineExtensions. |
||
66 | * |
||
67 | * @var int |
||
68 | */ |
||
69 | protected $right; |
||
70 | |||
71 | /** |
||
72 | * Required by DoctrineExtensions. |
||
73 | * |
||
74 | * @var int |
||
75 | */ |
||
76 | protected $level; |
||
77 | |||
78 | /** |
||
79 | * @var Collection|PermissionInterface[] |
||
80 | */ |
||
81 | protected $permissions; |
||
82 | |||
83 | /** |
||
84 | * @var array |
||
85 | */ |
||
86 | protected $securityRoles = []; |
||
87 | |||
88 | public function __construct() |
||
89 | { |
||
90 | $this->children = new ArrayCollection(); |
||
91 | $this->permissions = new ArrayCollection(); |
||
92 | $this->createdAt = new \DateTime(); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function __toString() |
||
99 | { |
||
100 | return $this->name; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function getId() |
||
107 | { |
||
108 | return $this->id; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | public function getCode() |
||
115 | { |
||
116 | return $this->code; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | public function setCode($code) |
||
123 | { |
||
124 | $this->code = $code; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | */ |
||
130 | public function getName() |
||
131 | { |
||
132 | return $this->name; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | public function setName($name) |
||
139 | { |
||
140 | $this->name = $name; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | public function getDescription() |
||
147 | { |
||
148 | return $this->description; |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | public function setDescription($description) |
||
155 | { |
||
156 | $this->description = $description; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * {@inheritdoc} |
||
161 | */ |
||
162 | public function getParent() |
||
163 | { |
||
164 | return $this->parent; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * {@inheritdoc} |
||
169 | */ |
||
170 | public function setParent(RoleInterface $role = null) |
||
171 | { |
||
172 | $this->parent = $role; |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * {@inheritdoc} |
||
177 | */ |
||
178 | public function getChildren() |
||
179 | { |
||
180 | return $this->children; |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | public function hasChildren() |
||
187 | { |
||
188 | return !$this->children->isEmpty(); |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * {@inheritdoc} |
||
193 | */ |
||
194 | public function addChild(RoleInterface $role) |
||
195 | { |
||
196 | if (!$this->hasChild($role)) { |
||
197 | $role->setParent($this); |
||
198 | $this->children->add($role); |
||
199 | } |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * {@inheritdoc} |
||
204 | */ |
||
205 | public function removeChild(RoleInterface $role) |
||
206 | { |
||
207 | if ($this->hasChild($role)) { |
||
208 | $role->setParent(null); |
||
0 ignored issues
–
show
|
|||
209 | $this->children->removeElement($role); |
||
210 | } |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * {@inheritdoc} |
||
215 | */ |
||
216 | public function hasChild(RoleInterface $role) |
||
217 | { |
||
218 | return $this->children->contains($role); |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * {@inheritdoc} |
||
223 | */ |
||
224 | public function getLeft() |
||
225 | { |
||
226 | return $this->left; |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * {@inheritdoc} |
||
231 | */ |
||
232 | public function setLeft($left) |
||
233 | { |
||
234 | $this->left = $left; |
||
235 | } |
||
236 | |||
237 | /** |
||
238 | * {@inheritdoc} |
||
239 | */ |
||
240 | public function getRight() |
||
241 | { |
||
242 | return $this->right; |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * {@inheritdoc} |
||
247 | */ |
||
248 | public function setRight($right) |
||
249 | { |
||
250 | $this->right = $right; |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * {@inheritdoc} |
||
255 | */ |
||
256 | public function getLevel() |
||
257 | { |
||
258 | return $this->level; |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * {@inheritdoc} |
||
263 | */ |
||
264 | public function setLevel($level) |
||
265 | { |
||
266 | $this->level = $level; |
||
267 | } |
||
268 | |||
269 | /** |
||
270 | * {@inheritdoc} |
||
271 | */ |
||
272 | public function getPermissions() |
||
273 | { |
||
274 | return $this->permissions; |
||
275 | } |
||
276 | |||
277 | /** |
||
278 | * {@inheritdoc} |
||
279 | */ |
||
280 | public function addPermission(PermissionInterface $permission) |
||
281 | { |
||
282 | if (!$this->hasPermission($permission)) { |
||
283 | $this->permissions->add($permission); |
||
284 | } |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * {@inheritdoc} |
||
289 | */ |
||
290 | public function removePermission(PermissionInterface $permission) |
||
291 | { |
||
292 | if ($this->hasPermission($permission)) { |
||
293 | $this->permissions->removeElement($permission); |
||
294 | } |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * {@inheritdoc} |
||
299 | */ |
||
300 | public function hasPermission(PermissionInterface $permission) |
||
301 | { |
||
302 | return $this->permissions->contains($permission); |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * {@inheritdoc} |
||
307 | */ |
||
308 | public function getSecurityRoles() |
||
309 | { |
||
310 | return $this->securityRoles; |
||
311 | } |
||
312 | |||
313 | /** |
||
314 | * {@inheritdoc} |
||
315 | */ |
||
316 | public function setSecurityRoles(array $securityRoles) |
||
317 | { |
||
318 | $this->securityRoles = $securityRoles; |
||
319 | } |
||
320 | } |
||
321 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: