CreateRole::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 3
Bugs 2 Features 0
Metric Value
cc 1
eloc 11
c 3
b 2
f 0
nc 1
nop 0
dl 0
loc 18
ccs 12
cts 12
cp 1
crap 1
rs 9.9
1
<?php
2
3
namespace Maklad\Permission\Commands;
4
5
use Illuminate\Console\Command;
6
use Maklad\Permission\Contracts\RoleInterface as Role;
7
8
/**
9
 * Class CreateRole
10
 * @package Maklad\Permission\Commands
11
 */
12
class CreateRole extends Command
13
{
14
    protected $signature = 'permission:create-role
15
        {name : The name of the role}
16
        {guard? : The name of the guard}
17
        {--permission=* : The name of the permission}';
18
19
    protected $description = 'Create a role';
20
21 4
    public function handle()
22
    {
23 4
        $roleClass       = \app(\config('permission.models.role'));
24
25 4
        $name        = $this->argument('name');
26 4
        $guard       = $this->argument('guard');
27 4
        $permissions = $this->option('permission');
28
29 4
        $role = $roleClass::create([
0 ignored issues
show
Bug introduced by
The method create() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        /** @scrutinizer ignore-call */ 
30
        $role = $roleClass::create([

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30 4
            'name'       => $name,
31 4
            'guard_name' => $guard
32
        ]);
33
34 4
        $this->info("Role `{$role->name}` created");
35
36 4
        $role->givePermissionTo($permissions);
37 4
        $permissionsStr = $role->permissions->implode('name', '`, `');
38 4
        $this->info("Permissions `{$permissionsStr}` has been given to role `{$role->name}`");
39 4
    }
40
}
41