1 | <?php namespace Arcanedev\LaravelAuth\Models; |
||
40 | class PermissionsGroup extends AbstractModel implements PermissionsGroupContract |
||
41 | { |
||
42 | /* ----------------------------------------------------------------- |
||
43 | | Properties |
||
44 | | ----------------------------------------------------------------- |
||
45 | */ |
||
46 | /** |
||
47 | * The attributes that are mass assignable. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $fillable = ['name', 'slug', 'description']; |
||
52 | |||
53 | /** |
||
54 | * The event map for the model. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $dispatchesEvents = [ |
||
59 | 'creating' => CreatingPermissionsGroup::class, |
||
60 | 'created' => CreatedPermissionsGroup::class, |
||
61 | 'updating' => UpdatingPermissionsGroup::class, |
||
62 | 'updated' => UpdatedPermissionsGroup::class, |
||
63 | 'saving' => SavingPermissionsGroup::class, |
||
64 | 'saved' => SavedPermissionsGroup::class, |
||
65 | 'deleting' => DeletingPermissionsGroup::class, |
||
66 | 'deleted' => DeletedPermissionsGroup::class, |
||
67 | ]; |
||
68 | |||
69 | /* ----------------------------------------------------------------- |
||
70 | | Constructor |
||
71 | | ----------------------------------------------------------------- |
||
72 | */ |
||
73 | /** |
||
74 | * Create a new Eloquent model instance. |
||
75 | * |
||
76 | * @param array $attributes |
||
77 | */ |
||
78 | 32 | public function __construct(array $attributes = []) |
|
86 | |||
87 | /* ------------------------------------------------------------------------------------------------ |
||
88 | | Relationships |
||
89 | | ------------------------------------------------------------------------------------------------ |
||
90 | */ |
||
91 | /** |
||
92 | * Permissions Groups has many permissions. |
||
93 | * |
||
94 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
95 | */ |
||
96 | 26 | public function permissions() |
|
103 | |||
104 | /* ----------------------------------------------------------------- |
||
105 | | Getters & Setters |
||
106 | | ----------------------------------------------------------------- |
||
107 | */ |
||
108 | /** |
||
109 | * Set the name attribute. |
||
110 | * |
||
111 | * @param string $name |
||
112 | */ |
||
113 | 26 | public function setNameAttribute($name) |
|
118 | |||
119 | /** |
||
120 | * Set the slug attribute. |
||
121 | * |
||
122 | * @param string $slug |
||
123 | */ |
||
124 | 26 | public function setSlugAttribute($slug) |
|
128 | |||
129 | /* ----------------------------------------------------------------- |
||
130 | | Main Methods |
||
131 | | ----------------------------------------------------------------- |
||
132 | */ |
||
133 | /** |
||
134 | * Create and attach a permission. |
||
135 | * |
||
136 | * @param array $attributes |
||
137 | * @param bool $reload |
||
138 | */ |
||
139 | 4 | public function createPermission(array $attributes, $reload = true) |
|
145 | |||
146 | /** |
||
147 | * Attach the permission to a group. |
||
148 | * |
||
149 | * @param \Arcanesoft\Contracts\Auth\Models\Permission $permission |
||
150 | * @param bool $reload |
||
151 | */ |
||
152 | 12 | public function attachPermission(&$permission, $reload = true) |
|
162 | |||
163 | /** |
||
164 | * Attach the permission by id to a group. |
||
165 | * |
||
166 | * @param int $id |
||
167 | * @param bool $reload |
||
168 | * |
||
169 | * @return \Arcanesoft\Contracts\Auth\Models\Permission|null |
||
170 | */ |
||
171 | 2 | public function attachPermissionById($id, $reload = true) |
|
180 | |||
181 | /** |
||
182 | * Attach a collection of permissions to the group. |
||
183 | * |
||
184 | * @param \Illuminate\Database\Eloquent\Collection|array $permissions |
||
185 | * @param bool $reload |
||
186 | * |
||
187 | * @return \Illuminate\Database\Eloquent\Collection|array |
||
188 | */ |
||
189 | 6 | public function attachPermissions($permissions, $reload = true) |
|
199 | |||
200 | /** |
||
201 | * Attach the permission from a group. |
||
202 | * |
||
203 | * @param \Arcanesoft\Contracts\Auth\Models\Permission $permission |
||
204 | * @param bool $reload |
||
205 | */ |
||
206 | 6 | public function detachPermission(&$permission, $reload = true) |
|
220 | |||
221 | /** |
||
222 | * Attach the permission by id to a group. |
||
223 | * |
||
224 | * @param int $id |
||
225 | * @param bool $reload |
||
226 | * |
||
227 | * @return \Arcanesoft\Contracts\Auth\Models\Permission |
||
228 | */ |
||
229 | 2 | public function detachPermissionById($id, $reload = true) |
|
236 | |||
237 | /** |
||
238 | * Detach multiple permissions by ids. |
||
239 | * |
||
240 | * @param array $ids |
||
241 | * @param bool $reload |
||
242 | * |
||
243 | * @return int |
||
244 | */ |
||
245 | 2 | public function detachPermissions(array $ids, $reload = true) |
|
255 | |||
256 | /** |
||
257 | * Detach all permissions from the group. |
||
258 | * |
||
259 | * @param bool $reload |
||
260 | * |
||
261 | * @return int |
||
262 | */ |
||
263 | 4 | public function detachAllPermissions($reload = true) |
|
273 | |||
274 | /* ----------------------------------------------------------------- |
||
275 | | Check Methods |
||
276 | | ----------------------------------------------------------------- |
||
277 | */ |
||
278 | /** |
||
279 | * Check if role has the given permission (Permission Model or Id). |
||
280 | * |
||
281 | * @param \Arcanesoft\Contracts\Auth\Models\Permission|int $id |
||
282 | * |
||
283 | * @return bool |
||
284 | */ |
||
285 | 16 | public function hasPermission($id) |
|
291 | |||
292 | /* ----------------------------------------------------------------- |
||
293 | | Other Methods |
||
294 | | ----------------------------------------------------------------- |
||
295 | */ |
||
296 | /** |
||
297 | * Get a permission from the group. |
||
298 | * |
||
299 | * @param \Arcanesoft\Contracts\Auth\Models\Permission|int $id |
||
300 | * |
||
301 | * @return \Arcanesoft\Contracts\Auth\Models\Permission|null |
||
302 | */ |
||
303 | 16 | private function getPermissionFromGroup($id) |
|
315 | |||
316 | /** |
||
317 | * Get a permission by id. |
||
318 | * |
||
319 | * @param int $id |
||
320 | * |
||
321 | * @return \Arcanesoft\Contracts\Auth\Models\Permission|null |
||
322 | */ |
||
323 | 4 | private function getPermissionById($id) |
|
327 | |||
328 | /** |
||
329 | * Load the permissions. |
||
330 | * |
||
331 | * @param bool $load |
||
332 | * |
||
333 | * @return self |
||
334 | */ |
||
335 | 22 | protected function loadPermissions($load = true) |
|
339 | } |
||
340 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.