Completed
Push — develop ( cc9a49...c1329f )
by Abdelrahman
09:49
created

SeedCommand   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 1
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 26 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Fort\Console\Commands;
6
7
use Illuminate\Console\Command;
8
9
class SeedCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'cortex:seed:fort';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Seed Cortex Fort Data.';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return void
29
     */
30
    public function handle(): void
31
    {
32
        $this->warn($this->description);
33
34
        $this->call('db:seed', ['--class' => 'CortexFortSeeder']);
35
36
        $user = [
37
            'username' => 'Fort',
38
            'email' => '[email protected]',
39
            'email_verified' => true,
40
            'is_active' => true,
41
        ];
42
43
        $user = tap(app('cortex.fort.user')->firstOrNew($user)->fill([
44
            'email_verified_at' => now(),
45
            'remember_token' => str_random(10),
46
            'password' => $password = str_random(),
47
        ]), function ($instance) {
48
            $instance->save();
49
        });
50
51
        // Assign roles
52
        $user->assign('superadmin');
53
54
        $this->table(['Username', 'Password'], [['username' => $user['username'], 'password' => $password]]);
55
    }
56
}
57