Passed
Push — master ( f218e6...f51c1b )
by Arthur
04:59
created

AuthorizationService::clearPermissionCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: anthony
5
 * Date: 22-10-18
6
 * Time: 14:18.
7
 */
8
9
namespace Modules\Authorization\Services;
10
11
use Modules\Authorization\Contracts\AuthorizationContract;
12
use Modules\Authorization\Entities\Permission;
13
use Modules\Authorization\Entities\Role;
14
15
class AuthorizationService implements AuthorizationContract
16
{
17
    public function createRole(string $role, array $permissions): Role
18
    {
19
        $role = Role::create([
20
            'name'       => $role,
21
            'guard_name' => 'api',
22
        ]);
23
        $role->givePermissionTo($permissions);
24
25
        return $role;
26
    }
27
28
    public function createPermissions(array $permissions): void
29
    {
30
        foreach ($permissions as $permission) {
31
            Permission::create([
32
                'name'       => $permission,
33
                'guard_name' => 'api',
34
            ]);
35
        }
36
    }
37
38
    public function clearPermissionCache() :void{
39
        app()['cache']->forget('spatie.permission.cache');
40
    }
41
}
42