Completed
Push — develop ( 9259d7...818a8c )
by Abdelrahman
01:45
created

SeedCommand::seedUsers()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 24
rs 8.9713
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Fort\Console\Commands;
6
7
use Illuminate\Console\Command;
8
use Rinvex\Support\Traits\SeederHelper;
9
10
class SeedCommand extends Command
11
{
12
    use SeederHelper;
13
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'cortex:seed:fort';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Seed Cortex Fort Data.';
27
28
    /**
29
     * Execute the console command.
30
     *
31
     * @return void
32
     */
33
    public function handle(): void
34
    {
35
        $this->warn($this->description);
36
37
        if ($this->ensureExistingDatabaseTables('rinvex/fort')) {
38
            $this->seedResources(app('rinvex.fort.ability'), realpath(__DIR__.'/../../../resources/data/abilities.json'), ['name', 'description', 'policy']);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 157 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
39
            $this->seedResources(app('rinvex.fort.role'), realpath(__DIR__.'/../../../resources/data/roles.json'), ['name', 'description'], function () {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 153 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
40
                // Grant abilities to roles
41
                app('rinvex.fort.role')->where('slug', 'admin')->first()->grantAbilities('superadmin-global');
42
            });
43
            $this->seedUsers();
44
        }
45
    }
46
47
    /**
48
     * Seed default users.
49
     *
50
     * @return void
51
     */
52
    protected function seedUsers(): void
53
    {
54
        $this->warn('Seeding Users:');
55
56
        $user = [
57
            'username' => 'Fort',
58
            'email' => '[email protected]',
59
            'email_verified' => true,
60
            'is_active' => true,
61
        ];
62
63
        $user = tap(app('rinvex.fort.user')->firstOrNew($user)->fill([
64
            'email_verified_at' => now(),
65
            'remember_token' => str_random(10),
66
            'password' => $password = str_random(),
67
        ]), function ($instance) {
68
            $instance->save();
69
        });
70
71
        // Assign roles to users
72
        $user->assignRoles('admin');
73
74
        $this->table(['Username', 'Password'], [['username' => $user['username'], 'password' => $password]]);
75
    }
76
}
77