RoleCreate::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Helldar\Roles\Console;
4
5
use Helldar\Roles\Models\Role;
6
use Helldar\Roles\Traits\Commands;
7
use Illuminate\Console\Command;
8
9
class RoleCreate extends Command
10
{
11
    use Commands;
12
13
    protected $signature = 'acl:role-create {slug}';
14
15
    protected $description = 'Create a new role';
16
17
    public function handle()
18
    {
19
        if ($this->roleIsExist()) {
20
            $this->error(sprintf('Role "%s" already exists!', $this->slug()));
21
22
            return;
23
        }
24
25
        $this->create();
26
    }
27
28
    protected function create()
29
    {
30
        $slug = $this->slug();
31
32
        $item = Role::create(compact('slug'));
33
34
        $this->info(sprintf('Role "%s" created successfully!', $slug));
35
        $this->line($item);
36
    }
37
}
38