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

AuthorizationService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createRole() 0 9 1
A createPermissions() 0 6 2
A clearPermissionCache() 0 2 1
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