Skip to content

Commit decd003

Browse files
committed
psr-2
1 parent 82fbabb commit decd003

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

src/HasRoles.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ public function assignRole($role)
3636
*
3737
* @param mixed $role
3838
*
39-
* @return boolean
39+
* @return bool
4040
*/
4141
public function hasRole($role)
4242
{
4343
if (is_string($role)) {
4444
return $this->roles->contains('name', $role);
4545
}
4646

47-
return !! $role->intersect($this->roles)->count();
47+
return !!$role->intersect($this->roles)->count();
4848
}
4949

5050
/**
5151
* Determine if the user may perform the given permission.
5252
*
5353
* @param Permission $permission
5454
*
55-
* @return boolean
55+
* @return bool
5656
*/
5757
public function hasPermission($permission)
5858
{

src/Models/Permission.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
2+
23
namespace Spatie\Permission\Models;
34

45
use Illuminate\Database\Eloquent\Model;
56
use Spatie\Permission\RefreshesPermissionCache;
67

78
class Permission extends Model
89
{
9-
1010
use RefreshesPermissionCache;
1111
/**
1212
* A permission can be applied to roles.

src/PermissionRegistrar.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public function __construct(Gate $gate, Repository $cache)
2727
$this->cache = $cache;
2828
}
2929

30+
/**
31+
* Register the permissions.
32+
*/
3033
public function registerPermissions()
3134
{
3235
try {
@@ -40,22 +43,23 @@ public function registerPermissions()
4043
}
4144
}
4245

46+
/**
47+
* Forget the cached permissions.
48+
*/
4349
public function forgetCachedPermissions()
4450
{
4551
$this->cache->forget($this->cacheKey);
4652
}
4753

54+
/**
55+
* Get the current permissions.
56+
*
57+
* @return mixed
58+
*/
4859
protected function getPermissions()
4960
{
50-
return $this->cache->rememberForever($this->cacheKey, function() {
61+
return $this->cache->rememberForever($this->cacheKey, function () {
5162
return Permission::with('roles')->get();
5263
});
53-
54-
55-
56-
57-
58-
59-
6064
}
6165
}

src/RefreshesPermissionCache.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22

33
namespace Spatie\Permission;
44

5-
trait RefreshesPermissionCache {
6-
5+
trait RefreshesPermissionCache
6+
{
77
public static function bootRefreshesPermissionCache()
88
{
9-
static::created(function($model) {
9+
static::created(function ($model) {
1010
$model->forgetCachedPermissions();
1111
});
1212

13-
static::updated(function($model) {
13+
static::updated(function ($model) {
1414
$model->forgetCachedPermissions();
1515
});
1616

17-
static::deleted(function($model) {
17+
static::deleted(function ($model) {
1818
$model->forgetCachedPermissions();
1919
});
2020
}
2121

22+
/**
23+
* Forget the cached permissions.
24+
*/
2225
public function forgetCachedPermissions()
2326
{
2427
app(PermissionRegistrar::class)->forgetCachedPermissions();

tests/User.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Spatie\Permission\Test;
34

45
use Illuminate\Database\Eloquent\Model;

0 commit comments

Comments
 (0)