@@ -16,7 +16,7 @@ |
||
| 16 | 16 | * LEVEL |
| 17 | 17 | * A Level has many users |
| 18 | 18 | * |
| 19 | - * @return mixed |
|
| 19 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 20 | 20 | */ |
| 21 | 21 | public function users() |
| 22 | 22 | { |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | { |
| 49 | 49 | parent::boot(); |
| 50 | 50 | |
| 51 | - static::deleting(function ($level) { |
|
| 51 | + static::deleting(function($level) { |
|
| 52 | 52 | $level->permissions()->where('level_id', $level->id)->update(['level_id' => null]); |
| 53 | 53 | foreach ($level->users as $user) { |
| 54 | 54 | $user->level()->dissociate()->save(); |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | * PERMISSION |
| 29 | 29 | * A permission belongs to many users |
| 30 | 30 | * |
| 31 | - * @return mixed |
|
| 31 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
|
| 32 | 32 | */ |
| 33 | 33 | public function users() |
| 34 | 34 | { |
@@ -134,7 +134,7 @@ |
||
| 134 | 134 | { |
| 135 | 135 | parent::boot(); |
| 136 | 136 | |
| 137 | - static::deleting(function ($permission) { |
|
| 137 | + static::deleting(function($permission) { |
|
| 138 | 138 | $permission->users()->detach(); |
| 139 | 139 | $permission->level()->dissociate()->save(); |
| 140 | 140 | }); |
@@ -99,11 +99,13 @@ |
||
| 99 | 99 | */ |
| 100 | 100 | protected function getUser($user) |
| 101 | 101 | { |
| 102 | - if (is_int($user)) |
|
| 103 | - $user = config('laravel-acl.user')::find($user); |
|
| 102 | + if (is_int($user)) { |
|
| 103 | + $user = config('laravel-acl.user')::find($user); |
|
| 104 | + } |
|
| 104 | 105 | |
| 105 | - if (!$user) |
|
| 106 | - throw new UserNotFoundException; |
|
| 106 | + if (!$user) { |
|
| 107 | + throw new UserNotFoundException; |
|
| 108 | + } |
|
| 107 | 109 | |
| 108 | 110 | return $user; |
| 109 | 111 | } |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * associated to a user by direct or |
| 263 | 263 | * inheritance |
| 264 | 264 | * |
| 265 | - * @return mixed |
|
| 265 | + * @return Collection |
|
| 266 | 266 | */ |
| 267 | 267 | protected function cacheGetAllPermissions() |
| 268 | 268 | { |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * USER & LEVEL |
| 286 | 286 | * Return a collection of permissions that |
| 287 | 287 | * are inherited from a higher level |
| 288 | - * @return mixed |
|
| 288 | + * @return Collection |
|
| 289 | 289 | */ |
| 290 | 290 | protected function cacheGetInheritedPermissions() |
| 291 | 291 | { |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | * Modify a given set of permissions, given the action to be taken |
| 348 | 348 | * |
| 349 | 349 | * @param $permissions |
| 350 | - * @param $action |
|
| 350 | + * @param string $action |
|
| 351 | 351 | * @return mixed |
| 352 | 352 | */ |
| 353 | 353 | protected function modifyPermissions($permissions, $action) |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | * |
| 381 | 381 | * @param $permissions |
| 382 | 382 | * @param $action |
| 383 | - * @param $model |
|
| 383 | + * @param string $model |
|
| 384 | 384 | * @return mixed |
| 385 | 385 | * @throws PermissionNotFoundException |
| 386 | 386 | */ |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * USER & LEVEL |
| 409 | 409 | * Helper function to handle adding or negating permissions |
| 410 | 410 | * |
| 411 | - * @param $model |
|
| 411 | + * @param string $model |
|
| 412 | 412 | * @param $permissionObjects |
| 413 | 413 | */ |
| 414 | 414 | protected function addOrNegate($model, $permissionObjects, $action) |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * USER & LEVEL |
| 425 | 425 | * Helper function to handle removing permissions |
| 426 | 426 | * |
| 427 | - * @param $model |
|
| 427 | + * @param string $model |
|
| 428 | 428 | * @param $permissionObjects |
| 429 | 429 | */ |
| 430 | 430 | protected function remove($model, $permissionObjects) |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | * USER & LEVEL |
| 444 | 444 | * Help function to handle syncing permissions |
| 445 | 445 | * |
| 446 | - * @param $model |
|
| 446 | + * @param string $model |
|
| 447 | 447 | * @param $permissionObjects |
| 448 | 448 | */ |
| 449 | 449 | protected function sync($model, $permissionObjects) |
@@ -105,11 +105,13 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function clearPermissions() |
| 107 | 107 | { |
| 108 | - if (get_class($this) == config('laravel-acl.user')) |
|
| 109 | - $this->permissions()->detach(); |
|
| 108 | + if (get_class($this) == config('laravel-acl.user')) { |
|
| 109 | + $this->permissions()->detach(); |
|
| 110 | + } |
|
| 110 | 111 | |
| 111 | - if (get_class($this) == config('laravel-acl.level')) |
|
| 112 | - config('laravel-acl.permission', Permission::class)::whereLevelId($this->id)->update(['level_id' => null]); |
|
| 112 | + if (get_class($this) == config('laravel-acl.level')) { |
|
| 113 | + config('laravel-acl.permission', Permission::class)::whereLevelId($this->id)->update(['level_id' => null]); |
|
| 114 | + } |
|
| 113 | 115 | } |
| 114 | 116 | |
| 115 | 117 | |
@@ -413,11 +415,13 @@ discard block |
||
| 413 | 415 | */ |
| 414 | 416 | protected function addOrNegate($model, $permissionObjects, $action) |
| 415 | 417 | { |
| 416 | - if ($model == 'User') |
|
| 417 | - $this->permissions()->attach($permissionObjects); |
|
| 418 | + if ($model == 'User') { |
|
| 419 | + $this->permissions()->attach($permissionObjects); |
|
| 420 | + } |
|
| 418 | 421 | |
| 419 | - if ($model == 'Level') |
|
| 420 | - $this->permissions()->saveMany($permissionObjects); |
|
| 422 | + if ($model == 'Level') { |
|
| 423 | + $this->permissions()->saveMany($permissionObjects); |
|
| 424 | + } |
|
| 421 | 425 | } |
| 422 | 426 | |
| 423 | 427 | /** |
@@ -429,8 +433,9 @@ discard block |
||
| 429 | 433 | */ |
| 430 | 434 | protected function remove($model, $permissionObjects) |
| 431 | 435 | { |
| 432 | - if ($model == 'User') |
|
| 433 | - $this->permissions()->detach($permissionObjects); |
|
| 436 | + if ($model == 'User') { |
|
| 437 | + $this->permissions()->detach($permissionObjects); |
|
| 438 | + } |
|
| 434 | 439 | |
| 435 | 440 | if ($model == 'Level') { |
| 436 | 441 | config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) { |
@@ -448,8 +453,9 @@ discard block |
||
| 448 | 453 | */ |
| 449 | 454 | protected function sync($model, $permissionObjects) |
| 450 | 455 | { |
| 451 | - if ($model == 'User') |
|
| 452 | - $this->permissions()->sync($permissionObjects); |
|
| 456 | + if ($model == 'User') { |
|
| 457 | + $this->permissions()->sync($permissionObjects); |
|
| 458 | + } |
|
| 453 | 459 | |
| 454 | 460 | if ($model == 'Level') { |
| 455 | 461 | $this->clearPermissions(); |
@@ -472,14 +478,17 @@ discard block |
||
| 472 | 478 | */ |
| 473 | 479 | protected function getPermission($permission) |
| 474 | 480 | { |
| 475 | - if (is_string($permission)) |
|
| 476 | - $permission = config('laravel-acl.permission', Permission::class)::whereName($permission)->first(); |
|
| 481 | + if (is_string($permission)) { |
|
| 482 | + $permission = config('laravel-acl.permission', Permission::class)::whereName($permission)->first(); |
|
| 483 | + } |
|
| 477 | 484 | |
| 478 | - if (is_int($permission)) |
|
| 479 | - $permission = config('laravel-acl.permission', Permission::class)::find($permission); |
|
| 485 | + if (is_int($permission)) { |
|
| 486 | + $permission = config('laravel-acl.permission', Permission::class)::find($permission); |
|
| 487 | + } |
|
| 480 | 488 | |
| 481 | - if (!$permission) |
|
| 482 | - throw new PermissionNotFoundException; |
|
| 489 | + if (!$permission) { |
|
| 490 | + throw new PermissionNotFoundException; |
|
| 491 | + } |
|
| 483 | 492 | |
| 484 | 493 | return $permission; |
| 485 | 494 | } |
@@ -36,8 +36,7 @@ discard block |
||
| 36 | 36 | $level = $this->getLevel($level); |
| 37 | 37 | |
| 38 | 38 | return get_class($this) == config('laravel-acl.level') ? |
| 39 | - $this->rank <= $level->rank : |
|
| 40 | - $this->level->rank <= $level->rank; |
|
| 39 | + $this->rank <= $level->rank : $this->level->rank <= $level->rank; |
|
| 41 | 40 | } |
| 42 | 41 | |
| 43 | 42 | /** |
@@ -131,7 +130,7 @@ discard block |
||
| 131 | 130 | return \Cache::remember( |
| 132 | 131 | 'laravel-acl.getAllPermissionsFor' . $model . '_' . $this->id, |
| 133 | 132 | config('laravel-acl.cacheMinutes'), |
| 134 | - function () { |
|
| 133 | + function() { |
|
| 135 | 134 | return $this->cacheGetAllPermissions(); |
| 136 | 135 | } |
| 137 | 136 | ); |
@@ -153,7 +152,7 @@ discard block |
||
| 153 | 152 | return \Cache::remember( |
| 154 | 153 | 'laravel-acl.getInheritedPermissionsFor' . $model . '_' . $this->id, |
| 155 | 154 | config('laravel-acl.cacheMinutes'), |
| 156 | - function () { |
|
| 155 | + function() { |
|
| 157 | 156 | return $this->cacheGetInheritedPermissions(); |
| 158 | 157 | } |
| 159 | 158 | ); |
@@ -175,7 +174,7 @@ discard block |
||
| 175 | 174 | return \Cache::remember( |
| 176 | 175 | 'laravel-acl.getAvailablePermissionsFor' . $model . '_' . $this->id, |
| 177 | 176 | config('laravel-acl.cacheMinutes'), |
| 178 | - function () { |
|
| 177 | + function() { |
|
| 179 | 178 | return $this->cacheGetAvailablePermissions(); |
| 180 | 179 | } |
| 181 | 180 | ); |
@@ -198,7 +197,7 @@ discard block |
||
| 198 | 197 | return \Cache::remember( |
| 199 | 198 | 'laravel-acl.hasPermissionTo_' . $model . '_' . $this->id . '_Permission_' . $permission, |
| 200 | 199 | config('laravel-acl.cacheMinutes'), |
| 201 | - function () use ($permission) { |
|
| 200 | + function() use ($permission) { |
|
| 202 | 201 | return $this->cacheHasPermissionTo($permission); |
| 203 | 202 | } |
| 204 | 203 | ); |
@@ -215,8 +214,7 @@ discard block |
||
| 215 | 214 | public function isLowerThan($other) |
| 216 | 215 | { |
| 217 | 216 | return get_class($this) == config('laravel-acl.user') ? |
| 218 | - $this->level->rank > $other->level->rank : |
|
| 219 | - $this->rank > $other->rank; |
|
| 217 | + $this->level->rank > $other->level->rank : $this->rank > $other->rank; |
|
| 220 | 218 | } |
| 221 | 219 | |
| 222 | 220 | /** |
@@ -230,8 +228,7 @@ discard block |
||
| 230 | 228 | public function isHigherThan($other) |
| 231 | 229 | { |
| 232 | 230 | return get_class($this) == config('laravel-acl.user') ? |
| 233 | - $this->level->rank < $other->level->rank : |
|
| 234 | - $this->rank < $other->rank; |
|
| 231 | + $this->level->rank < $other->level->rank : $this->rank < $other->rank; |
|
| 235 | 232 | } |
| 236 | 233 | |
| 237 | 234 | /** |
@@ -245,8 +242,7 @@ discard block |
||
| 245 | 242 | public function isEqualTo($other) |
| 246 | 243 | { |
| 247 | 244 | return get_class($this) == config('laravel-acl.user') ? |
| 248 | - $this->level->rank == $other->level->rank : |
|
| 249 | - $this->rank == $other->rank; |
|
| 245 | + $this->level->rank == $other->level->rank : $this->rank == $other->rank; |
|
| 250 | 246 | } |
| 251 | 247 | |
| 252 | 248 | |
@@ -265,14 +261,13 @@ discard block |
||
| 265 | 261 | protected function cacheGetAllPermissions() |
| 266 | 262 | { |
| 267 | 263 | $rank = get_class($this) == config('laravel-acl.level') ? |
| 268 | - $this->rank : |
|
| 269 | - $this->level->rank; |
|
| 264 | + $this->rank : $this->level->rank; |
|
| 270 | 265 | |
| 271 | 266 | $levels = config('laravel-acl.level', Level::class)::where('rank', '>=', $rank)->with('permissions')->get(); |
| 272 | 267 | |
| 273 | 268 | $allPerms = new Collection(); |
| 274 | 269 | |
| 275 | - $levels->each(function ($level, $key) use (&$allPerms) { |
|
| 270 | + $levels->each(function($level, $key) use (&$allPerms) { |
|
| 276 | 271 | $allPerms = $allPerms->merge($level->permissions); |
| 277 | 272 | }); |
| 278 | 273 | |
@@ -288,16 +283,14 @@ discard block |
||
| 288 | 283 | protected function cacheGetInheritedPermissions() |
| 289 | 284 | { |
| 290 | 285 | $rank = get_class($this) == config('laravel-acl.level') ? |
| 291 | - $this->rank : |
|
| 292 | - $this->level->rank; |
|
| 286 | + $this->rank : $this->level->rank; |
|
| 293 | 287 | |
| 294 | 288 | $levels = get_class($this) == config('laravel-acl.user') ? |
| 295 | - config('laravel-acl.level', Level::class)::where('rank', '>=', $rank)->with('permissions')->get() : |
|
| 296 | - config('laravel-acl.level', Level::class)::where('rank', '>', $rank)->with('permissions')->get(); |
|
| 289 | + config('laravel-acl.level', Level::class)::where('rank', '>=', $rank)->with('permissions')->get() : config('laravel-acl.level', Level::class)::where('rank', '>', $rank)->with('permissions')->get(); |
|
| 297 | 290 | |
| 298 | 291 | $inheritedPerms = new Collection(); |
| 299 | 292 | |
| 300 | - $levels->each(function ($level, $key) use (&$inheritedPerms) { |
|
| 293 | + $levels->each(function($level, $key) use (&$inheritedPerms) { |
|
| 301 | 294 | $inheritedPerms = $inheritedPerms->merge($level->permissions->load('level')); |
| 302 | 295 | }); |
| 303 | 296 | |
@@ -394,8 +387,7 @@ discard block |
||
| 394 | 387 | $permissionsObjects[$permission->id] = ['negated' => true]; |
| 395 | 388 | } else { |
| 396 | 389 | $model == 'User' ? |
| 397 | - array_push($permissionsObjects, $permission->id) : |
|
| 398 | - array_push($permissionsObjects, $permission); |
|
| 390 | + array_push($permissionsObjects, $permission->id) : array_push($permissionsObjects, $permission); |
|
| 399 | 391 | } |
| 400 | 392 | } |
| 401 | 393 | |
@@ -431,7 +423,7 @@ discard block |
||
| 431 | 423 | $this->permissions()->detach($permissionObjects); |
| 432 | 424 | |
| 433 | 425 | if ($model == 'Level') { |
| 434 | - config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) { |
|
| 426 | + config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function($permission) { |
|
| 435 | 427 | return $permission->id; |
| 436 | 428 | }, $permissionObjects))->update(['level_id' => null]); |
| 437 | 429 | } |
@@ -452,7 +444,7 @@ discard block |
||
| 452 | 444 | if ($model == 'Level') { |
| 453 | 445 | $this->clearPermissions(); |
| 454 | 446 | |
| 455 | - config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) { |
|
| 447 | + config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function($permission) { |
|
| 456 | 448 | return $permission->id; |
| 457 | 449 | }, $permissionObjects)) |
| 458 | 450 | ->update(['level_id' => $this->id]); |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | return \Cache::remember( |
| 50 | 50 | 'laravel-acl.getNegatedPermissionsForUser_' . $this->id, |
| 51 | 51 | config('laravel-acl.cacheMinutes'), |
| 52 | - function () { |
|
| 52 | + function() { |
|
| 53 | 53 | return $this->cacheGetNegatedPermissions(); |
| 54 | 54 | } |
| 55 | 55 | ); |
@@ -12,9 +12,9 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function boot() |
| 14 | 14 | { |
| 15 | - if($this->app->runningInConsole()) { |
|
| 15 | + if ($this->app->runningInConsole()) { |
|
| 16 | 16 | $this->publishFiles(); |
| 17 | - $this->loadMigrationsFrom(__DIR__.'/../../../migrations'); |
|
| 17 | + $this->loadMigrationsFrom(__DIR__ . '/../../../migrations'); |
|
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | 20 | |
@@ -2,8 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace z1haze\Acl\Traits; |
| 4 | 4 | |
| 5 | -use z1haze\Acl\Exceptions\LevelNotFoundException; |
|
| 6 | 5 | use Illuminate\Support\Facades\Cache; |
| 6 | +use z1haze\Acl\Exceptions\LevelNotFoundException; |
|
| 7 | 7 | use z1haze\Acl\Models\Level; |
| 8 | 8 | |
| 9 | 9 | trait UserAndPermission |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | return Cache::remember( |
| 61 | 61 | 'laravel-acl.getLevelFor' . $model . '_' . $this->id, |
| 62 | 62 | config('laravel-acl.cacheMinutes'), |
| 63 | - function () { |
|
| 63 | + function() { |
|
| 64 | 64 | return $this->cacheGetLevel(); |
| 65 | 65 | } |
| 66 | 66 | ); |
@@ -94,14 +94,17 @@ |
||
| 94 | 94 | */ |
| 95 | 95 | protected function getALevel($level) |
| 96 | 96 | { |
| 97 | - if (is_string($level)) |
|
| 98 | - $level = config('laravel-acl.level', Level::class)::whereName($level)->first(); |
|
| 97 | + if (is_string($level)) { |
|
| 98 | + $level = config('laravel-acl.level', Level::class)::whereName($level)->first(); |
|
| 99 | + } |
|
| 99 | 100 | |
| 100 | - if (is_int($level)) |
|
| 101 | - $level = config('laravel-acl.level', Level::class)::find($level); |
|
| 101 | + if (is_int($level)) { |
|
| 102 | + $level = config('laravel-acl.level', Level::class)::find($level); |
|
| 103 | + } |
|
| 102 | 104 | |
| 103 | - if (!$level) |
|
| 104 | - throw new LevelNotFoundException(); |
|
| 105 | + if (!$level) { |
|
| 106 | + throw new LevelNotFoundException(); |
|
| 107 | + } |
|
| 105 | 108 | |
| 106 | 109 | return $level; |
| 107 | 110 | } |