Completed
Push — master ( d0a6e2...c1e6c3 )
by Stephen
07:22
created
src/z1haze/Acl/Traits/UserAndLevel.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -354,7 +354,7 @@
 block discarded – undo
354 354
      * Modify a given set of permissions, given the action to be taken
355 355
      *
356 356
      * @param $permissions
357
-     * @param $action
357
+     * @param string $action
358 358
      */
359 359
     protected function modifyPermissions($permissions, $action)
360 360
     {
Please login to merge, or discard this patch.
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@
 block discarded – undo
3 3
 namespace z1haze\Acl\Traits;
4 4
 
5 5
 use Illuminate\Support\Collection;
6
+use Illuminate\Support\Facades\Cache;
6 7
 use ReflectionClass;
7 8
 use z1haze\Acl\Exceptions\PermissionNotFoundException;
8
-use Illuminate\Support\Facades\Cache;
9 9
 use z1haze\Acl\Models\Level;
10 10
 use z1haze\Acl\Models\Permission;
11 11
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -13 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         return Cache::remember(
123 123
             'laravel-acl.getPermissionsFor' . (new ReflectionClass($this))->getShortName() . '_' . $this->id,
124 124
             config('laravel-acl.cacheMinutes'),
125
-            function () {
125
+            function() {
126 126
                 return $this->cachegetPermissions();
127 127
             }
128 128
         );
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
         return Cache::remember(
143 143
             'laravel-acl.getAllPermissionsFor' . (new ReflectionClass($this))->getShortName() . '_' . $this->id,
144 144
             config('laravel-acl.cacheMinutes'),
145
-            function () {
145
+            function() {
146 146
                 return $this->cacheGetAllPermissions();
147 147
             }
148 148
         );
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
         return Cache::remember(
163 163
             'laravel-acl.getInheritedPermissionsFor' . (new ReflectionClass($this))->getShortName() . '_' . $this->id,
164 164
             config('laravel-acl.cacheMinutes'),
165
-            function () {
165
+            function() {
166 166
                 return $this->cacheGetInheritedPermissions();
167 167
             }
168 168
         );
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         return Cache::remember(
183 183
             'laravel-acl.getAvailablePermissionsFor' . (new ReflectionClass($this))->getShortName() . '_' . $this->id,
184 184
             config('laravel-acl.cacheMinutes'),
185
-            function () {
185
+            function() {
186 186
                 return $this->cacheGetAvailablePermissions();
187 187
             }
188 188
         );
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
         return Cache::remember(
204 204
             'laravel-acl.hasPermissionTo_' . (new ReflectionClass($this))->getShortName() . '_' . $this->id . '_Permission_' . $permission,
205 205
             config('laravel-acl.cacheMinutes'),
206
-            function () use ($permission) {
206
+            function() use ($permission) {
207 207
                 return $this->cacheHasPermissionTo($permission);
208 208
             }
209 209
         );
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 
282 282
         $allPerms = new Collection();
283 283
 
284
-        $levels->each(function ($level, $key) use (&$allPerms) {
284
+        $levels->each(function($level, $key) use (&$allPerms) {
285 285
             $allPerms = $allPerms->merge($level->permissions);
286 286
         });
287 287
 
@@ -300,12 +300,11 @@  discard block
 block discarded – undo
300 300
         $rank = is_a($this, config('laravel-acl.level'), true) ? $this->rank : $this->level->rank;
301 301
 
302 302
         $levels = is_a($this, config('laravel-acl.user'), true) ?
303
-            config('laravel-acl.level', Level::class)::where('rank', '>=', $rank)->with('permissions')->get() :
304
-            config('laravel-acl.level', Level::class)::where('rank', '>', $rank)->with('permissions')->get();
303
+            config('laravel-acl.level', Level::class)::where('rank', '>=', $rank)->with('permissions')->get() : config('laravel-acl.level', Level::class)::where('rank', '>', $rank)->with('permissions')->get();
305 304
 
306 305
         $inheritedPerms = new Collection();
307 306
 
308
-        $levels->each(function ($level, $key) use (&$inheritedPerms) {
307
+        $levels->each(function($level, $key) use (&$inheritedPerms) {
309 308
             $inheritedPerms = $inheritedPerms->merge($level->permissions->load('level'));
310 309
         });
311 310
 
@@ -399,8 +398,7 @@  discard block
 block discarded – undo
399 398
                 $permissionsObjects[$permission->id] = ['negated' => true];
400 399
             } else {
401 400
                 is_a($this, config('laravel-acl.user')) ?
402
-                    array_push($permissionsObjects, $permission->id) :
403
-                    array_push($permissionsObjects, $permission);
401
+                    array_push($permissionsObjects, $permission->id) : array_push($permissionsObjects, $permission);
404 402
             }
405 403
         }
406 404
 
@@ -434,7 +432,7 @@  discard block
 block discarded – undo
434 432
             $this->permissions()->detach($permissionObjects);
435 433
 
436 434
         if (is_a($this, config('laravel-acl.level'))) {
437
-            config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) {
435
+            config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function($permission) {
438 436
                 return $permission->id;
439 437
             }, $permissionObjects))->update(['level_id' => null]);
440 438
         }
@@ -454,7 +452,7 @@  discard block
 block discarded – undo
454 452
         if (is_a($this, config('laravel-acl.level'))) {
455 453
             $this->clearPermissions();
456 454
 
457
-            config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) {
455
+            config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function($permission) {
458 456
                 return $permission->id;
459 457
             }, $permissionObjects))
460 458
                 ->update(['level_id' => $this->id]);
Please login to merge, or discard this patch.
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -101,11 +101,13 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public function clearPermissions()
103 103
     {
104
-        if (is_a($this, config('laravel-acl.user'), true))
105
-            $this->permissions()->detach();
104
+        if (is_a($this, config('laravel-acl.user'), true)) {
105
+                    $this->permissions()->detach();
106
+        }
106 107
 
107
-        if (is_a($this, config('laravel-acl.level'), true))
108
-            config('laravel-acl.permission', Permission::class)::whereLevelId($this->id)->update(['level_id' => null]);
108
+        if (is_a($this, config('laravel-acl.level'), true)) {
109
+                    config('laravel-acl.permission', Permission::class)::whereLevelId($this->id)->update(['level_id' => null]);
110
+        }
109 111
     }
110 112
 
111 113
     /**
@@ -415,11 +417,13 @@  discard block
 block discarded – undo
415 417
      */
416 418
     protected function addOrNegate($permissionObjects)
417 419
     {
418
-        if (is_a($this, config('laravel-acl.user')))
419
-            $this->permissions()->attach($permissionObjects);
420
+        if (is_a($this, config('laravel-acl.user'))) {
421
+                    $this->permissions()->attach($permissionObjects);
422
+        }
420 423
 
421
-        if (is_a($this, config('laravel-acl.level')))
422
-            $this->permissions()->saveMany($permissionObjects);
424
+        if (is_a($this, config('laravel-acl.level'))) {
425
+                    $this->permissions()->saveMany($permissionObjects);
426
+        }
423 427
     }
424 428
 
425 429
     /**
@@ -430,8 +434,9 @@  discard block
 block discarded – undo
430 434
      */
431 435
     protected function remove($permissionObjects)
432 436
     {
433
-        if (is_a($this, config('laravel-acl.user')))
434
-            $this->permissions()->detach($permissionObjects);
437
+        if (is_a($this, config('laravel-acl.user'))) {
438
+                    $this->permissions()->detach($permissionObjects);
439
+        }
435 440
 
436 441
         if (is_a($this, config('laravel-acl.level'))) {
437 442
             config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) {
@@ -448,8 +453,9 @@  discard block
 block discarded – undo
448 453
      */
449 454
     protected function sync($permissionObjects)
450 455
     {
451
-        if (is_a($this, config('laravel-acl.user')))
452
-            $this->permissions()->sync($permissionObjects);
456
+        if (is_a($this, config('laravel-acl.user'))) {
457
+                    $this->permissions()->sync($permissionObjects);
458
+        }
453 459
 
454 460
         if (is_a($this, config('laravel-acl.level'))) {
455 461
             $this->clearPermissions();
@@ -472,14 +478,17 @@  discard block
 block discarded – undo
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
     }
Please login to merge, or discard this patch.