Completed
Push — master ( b6e961...8692a9 )
by Abdelrahman
15:05 queued 12:57
created

SeedCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 2
B seedUsers() 0 24 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Fort\Console\Commands;
6
7
use Carbon\Carbon;
8
use Illuminate\Console\Command;
9
use Rinvex\Support\Traits\SeederHelper;
10
11
class SeedCommand extends Command
12
{
13
    use SeederHelper;
14
15
    /**
16
     * The name and signature of the console command.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'rinvex:seed:fort';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Seed Rinvex Fort Data.';
28
29
    /**
30
     * Execute the console command.
31
     *
32
     * @return void
33
     */
34
    public function handle()
35
    {
36
        $this->warn($this->description);
37
38
        if ($this->ensureExistingDatabaseTables('rinvex/fort')) {
39
            $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...
40
            $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...
41
                // Grant abilities to roles
42
                app('rinvex.fort.role')->where('slug', 'admin')->first()->grantAbilities('superadmin', 'global');
43
            });
44
            $this->seedUsers();
45
        }
46
    }
47
48
    /**
49
     * Seed default users.
50
     *
51
     * @return void
52
     */
53
    protected function seedUsers()
54
    {
55
        $this->warn('Seeding Users:');
56
57
        $user = [
58
            'username' => 'Fort',
59
            'email' => '[email protected]',
60
            'email_verified' => true,
61
            'is_active' => true,
62
        ];
63
64
        $user = tap(app('rinvex.fort.user')->firstOrNew($user)->fill([
65
            'email_verified_at' => Carbon::now(),
66
            'remember_token' => str_random(10),
67
            'password' => $password = str_random(),
68
        ]), function ($instance) {
69
            $instance->save();
70
        });
71
72
        // Assign roles to users
73
        $user->assignRoles('admin');
74
75
        $this->table(['Username', 'Password'], [['username' => $user['username'], 'password' => $password]]);
76
    }
77
}
78