SeedCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 91
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createAdmin() 0 18 1
A createGuardian() 0 15 1
A handle() 0 20 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Console\Commands;
6
7
use Cortex\Auth\Models\Admin;
8
use Illuminate\Console\Command;
9
use Cortex\Auth\Models\Guardian;
10
11
class SeedCommand extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'cortex:seed:auth';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Seed Cortex Auth Data.';
26
27
    /**
28
     * Execute the console command.
29
     *
30
     * @return void
31
     */
32
    public function handle(): void
33
    {
34
        $this->alert($this->description);
35
36
        $this->call('db:seed', ['--class' => 'CortexAuthSeeder']);
37
38
        // Create models
39
        $admin = $this->createAdmin($adminPassword = str_random());
0 ignored issues
show
Deprecated Code introduced by
The function str_random() has been deprecated with message: Str::random() should be used directly instead. Will be removed in Laravel 6.0.

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

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

Loading history...
40
        $guardian = $this->createGuardian($guardianPassword = str_random());
0 ignored issues
show
Deprecated Code introduced by
The function str_random() has been deprecated with message: Str::random() should be used directly instead. Will be removed in Laravel 6.0.

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

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

Loading history...
41
42
        // Assign roles
43
        $admin->assign('superadmin');
44
45
        $this->table(['Username', 'Password'], [
46
            ['username' => $admin['username'], 'password' => $adminPassword],
47
            ['username' => $guardian['username'], 'password' => $guardianPassword],
48
        ]);
49
50
        $this->line('');
51
    }
52
53
    /**
54
     * Create admin model.
55
     *
56
     * @param string $password
57
     *
58
     * @return \Cortex\Auth\Models\Admin
59
     */
60
    protected function createAdmin(string $password): Admin
61
    {
62
        $admin = [
63
            'is_active' => true,
64
            'username' => 'Admin',
65
            'given_name' => 'Admin',
66
            'family_name' => 'User',
67
            'email' => '[email protected]',
68
        ];
69
70
        return tap(app('cortex.auth.admin')->firstOrNew($admin)->fill([
71
            'remember_token' => str_random(10),
0 ignored issues
show
Deprecated Code introduced by
The function str_random() has been deprecated with message: Str::random() should be used directly instead. Will be removed in Laravel 6.0.

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

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

Loading history...
72
            'email_verified_at' => now(),
73
            'password' => $password,
74
        ]), function ($instance) {
75
            $instance->save();
76
        });
77
    }
78
79
    /**
80
     * Create guardian model.
81
     *
82
     * @param string $password
83
     *
84
     * @return \Cortex\Auth\Models\Guardian
85
     */
86
    protected function createGuardian(string $password): Guardian
87
    {
88
        $guardian = [
89
            'is_active' => true,
90
            'username' => 'Guardian',
91
            'email' => '[email protected]',
92
        ];
93
94
        return tap(app('cortex.auth.guardian')->firstOrNew($guardian)->fill([
95
            'remember_token' => str_random(10),
0 ignored issues
show
Deprecated Code introduced by
The function str_random() has been deprecated with message: Str::random() should be used directly instead. Will be removed in Laravel 6.0.

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

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

Loading history...
96
            'password' => $password,
97
        ]), function ($instance) {
98
            $instance->save();
99
        });
100
    }
101
}
102