Completed
Push — master ( 8b2ccd...ab2185 )
by Sherif
14:39
created

PassportInstallCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 2
1
<?php
2
3
namespace App\Modules\Core\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Laravel\Passport\ClientRepository;
7
8
class PassportInstallCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'module:passport:install
16
                            {--force : Overwrite keys they already exist}
17
                            {--length=4096 : The length of the private key}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Run the commands necessary to prepare Passport for use';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return void
30
     */
31
    public function handle(ClientRepository $client)
32
    {
33
        $this->call('passport:keys', ['--force' => $this->option('force'), '--length' => $this->option('length')]);
34
        if( ! \Core::oauthCLients()->first(['password_client' => 1])->count()) {
35
    
36
            $client = $client->createPasswordGrantClient(
37
                null, config('app.name'), 'http://localhost'
38
            );
39
            \DotenvEditor::setKey('PASSWORD_CLIENT_ID', $client->id);
40
            \DotenvEditor::setKey('PASSWORD_CLIENT_SECRET', $client->secret);
41
            \DotenvEditor::save();
42
        }
43
    }
44
}
45