SaltsGenerate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 20
dl 0
loc 38
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 6 2
A generateSalt() 0 6 1
1
<?php
2
3
namespace Presspack\Framework\Commands;
4
5
use RandomLib\Factory;
6
use SecurityLib\Strength;
7
use Illuminate\Console\Command;
0 ignored issues
show
Bug introduced by
The type Illuminate\Console\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Presspack\Framework\Support\Environment;
9
10
class SaltsGenerate extends Command
11
{
12
    protected $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_[]{}<>~`+=,.;:/?|';
13
14
    protected $keys = [
15
        'AUTH_KEY',
16
        'SECURE_AUTH_KEY',
17
        'LOGGED_IN_KEY',
18
        'NONCE_KEY',
19
        'AUTH_SALT',
20
        'SECURE_AUTH_SALT',
21
        'LOGGED_IN_SALT',
22
        'NONCE_SALT',
23
    ];
24
25
    protected $signature = 'salts:generate';
26
27
    protected $description = 'Generates Wordpress Salts and writes them to .env';
28
29
    public function __construct()
30
    {
31
        parent::__construct();
32
    }
33
34
    public function handle()
35
    {
36
        foreach ($this->keys as $key) {
37
            Environment::set($key, "\"{$this->generateSalt()}\"");
38
        }
39
        $this->info('Salts stored!');
40
    }
41
42
    public function generateSalt($length = 64)
43
    {
44
        $factory = new Factory();
45
        $generator = $factory->getGenerator(new Strength(Strength::MEDIUM));
46
47
        return $generator->generateString($length, $this->chars);
48
    }
49
}
50