Completed
Pull Request — master (#28)
by ARCANEDEV
02:46
created

UserTableSeeder::getAdminUserAttributes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 11
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php namespace Arcanesoft\Auth\Seeds\Foundation;
2
3
use Arcanedev\LaravelAuth\Services\UserConfirmator;
4
use Arcanedev\Support\Database\Seeder;
5
use Arcanesoft\Auth\Models\Role;
6
use Arcanesoft\Auth\Models\User;
7
use Carbon\Carbon;
8
9
/**
10
 * Class     UserTableSeeder
11
 *
12
 * @package  Arcanesoft\Auth\Seeds\Foundation
13
 * @author   ARCANEDEV <[email protected]>
14
 */
15
class UserTableSeeder extends Seeder
16
{
17
    /* -----------------------------------------------------------------
18
     |  Main Methods
19
     | -----------------------------------------------------------------
20
     */
21
22
    /**
23
     * Run the database seeds.
24
     */
25
    public function run()
26
    {
27
        $this->seedAdminUser();
28
    }
29
30
    /* -----------------------------------------------------------------
31
     |  Other Methods
32
     | -----------------------------------------------------------------
33
     */
34
35
    /**
36
     * Seed the admin account.
37
     */
38
    private function seedAdminUser()
39
    {
40
        tap(new User($this->getAdminUserAttributes()), function (User $admin) {
41
            $admin->save();
42
43
            /** @var  \Arcanesoft\Auth\Models\Role  $adminRole */
44
            $adminRole = Role::admin()->first();
45
            $adminRole->attachUser($admin);
46
        });
47
    }
48
49
    /**
50
     * Get the admin user's attributes.
51
     *
52
     * @return array
53
     */
54
    private function getAdminUserAttributes()
55
    {
56
        $now        = Carbon::now();
57
        $attributes = [
58
            'username'     => 'admin',
59
            'first_name'   => 'Super',
60
            'last_name'    => 'ADMIN',
61
            'email'        => env('ADMIN_EMAIL',    '[email protected]'),
62
            'password'     => env('ADMIN_PASSWORD', 'password'),
63
            'is_admin'     => true,
64
            'activated_at' => $now,
65
        ];
66
67
        if (UserConfirmator::isEnabled())
68
            $attributes['confirmed_at'] = $now;
69
70
        return $attributes;
71
    }
72
}
73