Passed
Push — master ( 8a373e...617e52 )
by Arthur
22:06
created

AuthorizationSeeder::createAdminRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Modules\Authorization\Database\Seeders;
4
5
use Illuminate\Database\Seeder;
6
use Modules\Authorization\Contracts\AuthorizationContract;
7
use Modules\Authorization\Managers\PermissionManager;
8
use Modules\Authorization\Managers\RoleManager;
9
use Modules\Authorization\Services\AuthorizationService;
10
11
class AuthorizationSeeder extends Seeder
12
{
13
    /**
14
     * @var AuthorizationService
15
     */
16
    protected $service;
17
18
    /**
19
     * AuthorizationSeeder constructor.
20
     *
21
     * @param $service
22
     */
23
    public function __construct(AuthorizationContract $service)
24
    {
25
        $this->service = $service;
0 ignored issues
show
Documentation Bug introduced by
$service is of type Modules\Authorization\Co...s\AuthorizationContract, but the property $service was declared to be of type Modules\Authorization\Se...es\AuthorizationService. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
26
    }
27
28
    /**
29
     * Run the database seeds.
30
     *
31
     * @return void
32
     */
33
    public function run()
34
    {
35
        $this->service->clearPermissionCache();
36
        $this->createPermissions();
37
        $this->createRoles();
38
    }
39
40
    protected function createPermissions(): void
41
    {
42
        $permissions = PermissionManager::getAllPermissions();
43
        $this->service->createPermissions(collect($permissions)->flatten()->toArray());
44
    }
45
46
    protected function createRoles(): void
47
    {
48
        foreach (RoleManager::ROLES as $role) {
49
            $this->service->createRole(strtolower($role::getRoleName()), $role::getPermissions());
50
        }
51
    }
52
}
53