CreateScopeCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 45
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 14 3
1
<?php
2
3
4
namespace Mvdstam\Oauth2ServerLaravel\Commands;
5
6
7
use Exception;
8
use Illuminate\Console\Command;
9
use Mvdstam\Oauth2ServerLaravel\Repositories\ScopeRepository;
10
11
class CreateScopeCommand extends Command
12
{
13
14
    /**
15
     * @var string
16
     */
17
    protected $signature = 'oauth2-server:create-scope {id?}';
18
19
    /**
20
     * @var string
21
     */
22
    protected $description = 'Create new scopes for your OAuth2 server';
23
24
    /**
25
     * @var ScopeRepository
26
     */
27
    protected $scopes;
28
29
    /**
30
     * CreateScopeCommand constructor.
31
     * @param ScopeRepository $scopes
32
     */
33 19
    public function __construct(ScopeRepository $scopes)
34
    {
35 19
        parent::__construct();
36
37 19
        $this->scopes = $scopes;
38 19
    }
39
40
41 5
    public function handle()
42
    {
43
        try {
44 5
            if (!($scopeId = $this->argument('id'))) {
45 1
                $scopeId = $this->ask('Enter scope ID');
46
            }
47
48 5
            $this->scopes->forceCreate(['id' => $scopeId]);
49 4
            $this->info('Scope created succesfully!');
50 2
        } catch (Exception $e) {
51 2
            $this->error("An error occurred: {$e->getMessage()}");
52 2
            return 1;
53
        }
54 4
    }
55
}
56