CreateScopeCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
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