Passed
Push — master ( 1dc943...5f0a93 )
by Arthur
08:24 queued 35s
created

AuthorizationService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createRole() 0 9 1
A createPermissions() 0 6 2
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $role could return the type Jenssegers\Mongodb\Eloquent\Model which includes types incompatible with the type-hinted return Modules\Authorization\Entities\Role. Consider adding an additional type-check to rule them out.
Loading history...
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