GenerateJwtSecretCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
c 0
b 0
f 0
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 10 2
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Str;
7
use Jackiedo\DotenvEditor\DotenvEditor;
8
9
class GenerateJwtSecretCommand extends Command
10
{
11
    protected $name = 'koel:generate-jwt-secret';
12
    protected $description = 'Set the JWTAuth secret key used to sign the tokens';
13
    private $dotenvEditor;
14
15 132
    public function __construct(DotenvEditor $dotenvEditor)
16
    {
17 132
        parent::__construct();
18
19 132
        $this->dotenvEditor = $dotenvEditor;
20 132
    }
21
22 2
    public function handle(): void
23
    {
24 2
        if (config('jwt.secret')) {
25 1
            $this->comment('JWT secret exists -- skipping');
26
27 1
            return;
28
        }
29
30 1
        $this->info('Generating JWT secret');
31 1
        $this->dotenvEditor->setKey('JWT_SECRET', Str::random(32))->save();
32 1
    }
33
}
34