Completed
Push — master ( 7eb1a4...254269 )
by LEUNG
03:41
created

JwtCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A configure() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace xiaodi\JWTAuth\Command;
6
7
use Nette\PhpGenerator\Helpers;
8
use Nette\PhpGenerator\PhpFile;
9
use think\console\Command;
10
use think\console\Input;
11
use think\console\Output;
12
13
function randomKey()
14
{
15
    $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~0123456789#$%^&';
16
    $pass = [];
17
    $alphaLength = strlen($alphabet) - 1;
18
    for ($i = 0; $i < 10; $i++) {
19
        $n = rand(0, $alphaLength);
20
        $pass[] = $alphabet[$n];
21
    }
22
23
    return implode($pass);
24
}
25
26
class JwtCommand extends Command
27
{
28
    protected function configure()
29
    {
30
        $this->setName('jwt:make')->setDescription('生成一个签名密钥');
31
    }
32
33
    protected function execute(Input $input, Output $output)
34
    {
35
        $file = new PhpFile();
36
        $file->addComment('Jwt 配置');
37
        $file->setStrictTypes();
38
39
        $config = config('jwt');
40
        $config['default']['signerKey'] = randomKey();
41
        $config = 'return ' . Helpers::dump($config) . ';';
0 ignored issues
show
Deprecated Code introduced by
The function Nette\PhpGenerator\Helpers::dump() has been deprecated: use Nette\PhpGenerator\Dumper::dump() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

41
        $config = 'return ' . /** @scrutinizer ignore-deprecated */ Helpers::dump($config) . ';';

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
42
43
        file_put_contents($this->app->getConfigPath() . 'jwt.php', $file . $config);
44
        $output->writeln('> success!');
45
    }
46
}
47