1 | <?php namespace Arcanedev\LaravelAuth\Models; |
||
40 | class PermissionsGroup extends AbstractModel implements PermissionsGroupContract |
||
41 | { |
||
42 | /* ----------------------------------------------------------------- |
||
43 | | Properties |
||
44 | | ----------------------------------------------------------------- |
||
45 | */ |
||
46 | |||
47 | /** |
||
48 | * The attributes that are mass assignable. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $fillable = ['name', 'slug', 'description']; |
||
53 | |||
54 | /** |
||
55 | * The event map for the model. |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $dispatchesEvents = [ |
||
60 | 'creating' => CreatingPermissionsGroup::class, |
||
61 | 'created' => CreatedPermissionsGroup::class, |
||
62 | 'updating' => UpdatingPermissionsGroup::class, |
||
63 | 'updated' => UpdatedPermissionsGroup::class, |
||
64 | 'saving' => SavingPermissionsGroup::class, |
||
65 | 'saved' => SavedPermissionsGroup::class, |
||
66 | 'deleting' => DeletingPermissionsGroup::class, |
||
67 | 'deleted' => DeletedPermissionsGroup::class, |
||
68 | ]; |
||
69 | |||
70 | /** |
||
71 | * The attributes that should be cast to native types. |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $casts = [ |
||
76 | 'id' => 'integer', |
||
77 | ]; |
||
78 | |||
79 | /* ----------------------------------------------------------------- |
||
80 | | Constructor |
||
81 | | ----------------------------------------------------------------- |
||
82 | */ |
||
83 | |||
84 | /** |
||
85 | * Create a new Eloquent model instance. |
||
86 | * |
||
87 | * @param array $attributes |
||
88 | */ |
||
89 | 32 | public function __construct(array $attributes = []) |
|
97 | |||
98 | /* ----------------------------------------------------------------- |
||
99 | | Relationships |
||
100 | | ----------------------------------------------------------------- |
||
101 | */ |
||
102 | |||
103 | /** |
||
104 | * Permissions Groups has many permissions. |
||
105 | * |
||
106 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
107 | */ |
||
108 | 26 | public function permissions() |
|
115 | |||
116 | /* ----------------------------------------------------------------- |
||
117 | | Getters & Setters |
||
118 | | ----------------------------------------------------------------- |
||
119 | */ |
||
120 | |||
121 | /** |
||
122 | * Set the name attribute. |
||
123 | * |
||
124 | * @param string $name |
||
125 | */ |
||
126 | 26 | public function setNameAttribute($name) |
|
131 | |||
132 | /** |
||
133 | * Set the slug attribute. |
||
134 | * |
||
135 | * @param string $slug |
||
136 | */ |
||
137 | 26 | public function setSlugAttribute($slug) |
|
141 | |||
142 | /* ----------------------------------------------------------------- |
||
143 | | Main Methods |
||
144 | | ----------------------------------------------------------------- |
||
145 | */ |
||
146 | |||
147 | /** |
||
148 | * Create and attach a permission. |
||
149 | * |
||
150 | * @param array $attributes |
||
151 | * @param bool $reload |
||
152 | */ |
||
153 | 4 | public function createPermission(array $attributes, $reload = true) |
|
159 | |||
160 | /** |
||
161 | * Attach the permission to a group. |
||
162 | * |
||
163 | * @param \Arcanesoft\Contracts\Auth\Models\Permission $permission |
||
164 | * @param bool $reload |
||
165 | */ |
||
166 | 12 | public function attachPermission(&$permission, $reload = true) |
|
176 | |||
177 | /** |
||
178 | * Attach the permission by id to a group. |
||
179 | * |
||
180 | * @param int $id |
||
181 | * @param bool $reload |
||
182 | * |
||
183 | * @return \Arcanesoft\Contracts\Auth\Models\Permission|null |
||
184 | */ |
||
185 | 2 | public function attachPermissionById($id, $reload = true) |
|
194 | |||
195 | /** |
||
196 | * Attach a collection of permissions to the group. |
||
197 | * |
||
198 | * @param \Illuminate\Database\Eloquent\Collection|array $permissions |
||
199 | * @param bool $reload |
||
200 | * |
||
201 | * @return \Illuminate\Database\Eloquent\Collection|array |
||
202 | */ |
||
203 | 6 | public function attachPermissions($permissions, $reload = true) |
|
213 | |||
214 | /** |
||
215 | * Attach the permission from a group. |
||
216 | * |
||
217 | * @param \Arcanesoft\Contracts\Auth\Models\Permission $permission |
||
218 | * @param bool $reload |
||
219 | */ |
||
220 | 6 | public function detachPermission(&$permission, $reload = true) |
|
234 | |||
235 | /** |
||
236 | * Attach the permission by id to a group. |
||
237 | * |
||
238 | * @param int $id |
||
239 | * @param bool $reload |
||
240 | * |
||
241 | * @return \Arcanesoft\Contracts\Auth\Models\Permission |
||
242 | */ |
||
243 | 2 | public function detachPermissionById($id, $reload = true) |
|
250 | |||
251 | /** |
||
252 | * Detach multiple permissions by ids. |
||
253 | * |
||
254 | * @param array $ids |
||
255 | * @param bool $reload |
||
256 | * |
||
257 | * @return int |
||
258 | */ |
||
259 | 2 | public function detachPermissions(array $ids, $reload = true) |
|
269 | |||
270 | /** |
||
271 | * Detach all permissions from the group. |
||
272 | * |
||
273 | * @param bool $reload |
||
274 | * |
||
275 | * @return int |
||
276 | */ |
||
277 | 4 | public function detachAllPermissions($reload = true) |
|
287 | |||
288 | /* ----------------------------------------------------------------- |
||
289 | | Check Methods |
||
290 | | ----------------------------------------------------------------- |
||
291 | */ |
||
292 | |||
293 | /** |
||
294 | * Check if role has the given permission (Permission Model or Id). |
||
295 | * |
||
296 | * @param \Arcanesoft\Contracts\Auth\Models\Permission|int $id |
||
297 | * |
||
298 | * @return bool |
||
299 | */ |
||
300 | 16 | public function hasPermission($id) |
|
306 | |||
307 | /* ----------------------------------------------------------------- |
||
308 | | Other Methods |
||
309 | | ----------------------------------------------------------------- |
||
310 | */ |
||
311 | |||
312 | /** |
||
313 | * Get a permission from the group. |
||
314 | * |
||
315 | * @param \Arcanesoft\Contracts\Auth\Models\Permission|int $id |
||
316 | * |
||
317 | * @return \Arcanesoft\Contracts\Auth\Models\Permission|null |
||
318 | */ |
||
319 | 16 | private function getPermissionFromGroup($id) |
|
331 | |||
332 | /** |
||
333 | * Get a permission by id. |
||
334 | * |
||
335 | * @param int $id |
||
336 | * |
||
337 | * @return \Arcanesoft\Contracts\Auth\Models\Permission|null |
||
338 | */ |
||
339 | 4 | private function getPermissionById($id) |
|
343 | |||
344 | /** |
||
345 | * Load the permissions. |
||
346 | * |
||
347 | * @param bool $load |
||
348 | * |
||
349 | * @return self |
||
350 | */ |
||
351 | 22 | protected function loadPermissions($load = true) |
|
355 | } |
||
356 |
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.