UserSeeder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 7
nc 1
nop 3
1
<?php namespace Anomaly\UsersModule\User;
2
3
use Anomaly\Streams\Platform\Database\Seeder\Seeder;
4
use Anomaly\UsersModule\Role\Contract\RoleRepositoryInterface;
5
use Anomaly\UsersModule\User\Contract\UserInterface;
6
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
7
8
/**
9
 * Class UserSeeder
10
 *
11
 * @link          http://pyrocms.com/
12
 * @author        PyroCMS, Inc. <[email protected]>
13
 * @author        Ryan Thompson <[email protected]>
14
 */
15
class UserSeeder extends Seeder
16
{
17
18
    /**
19
     * The user repository.
20
     *
21
     * @var UserRepositoryInterface
22
     */
23
    protected $users;
24
25
    /**
26
     * The role repository.
27
     *
28
     * @var RoleRepositoryInterface
29
     */
30
    protected $roles;
31
32
    /**
33
     * The activator utility.
34
     *
35
     * @var UserActivator
36
     */
37
    protected $activator;
38
39
    /**
40
     * Create a new UserSeeder instance.
41
     *
42
     * @param UserRepositoryInterface $users
43
     * @param RoleRepositoryInterface $roles
44
     * @param UserActivator           $activator
45
     */
46
    public function __construct(
47
        UserRepositoryInterface $users,
48
        RoleRepositoryInterface $roles,
49
        UserActivator $activator
50
    ) {
51
        $this->users     = $users;
52
        $this->roles     = $roles;
53
        $this->activator = $activator;
54
    }
55
56
    /**
57
     * Run the seeder.
58
     */
59
    public function run()
60
    {
61
        $this->users->truncate();
62
63
        $admin = $this->roles->findBySlug('admin');
64
        $user  = $this->roles->findBySlug('user');
65
66
        /* @var UserInterface $administrator */
67
        $administrator = $this->users->create(
68
            [
69
                'display_name' => 'Administrator',
70
                'email'        => env('ADMIN_EMAIL'),
71
                'username'     => env('ADMIN_USERNAME'),
72
                'password'     => env('ADMIN_PASSWORD'),
73
            ]
74
        );
75
76
        /* @var UserInterface $demo */
77
        $demo = $this->users->create(
78
            [
79
                'display_name' => 'Demo User',
80
                'email'        => '[email protected]',
81
                'password'     => 'password',
82
                'username'     => 'demo',
83
            ]
84
        );
85
86
        $demo->roles()->sync([$user->getId()]);
87
        $administrator->roles()->sync([$admin->getId()]);
88
89
        $this->activator->force($demo);
90
        $this->activator->force($administrator);
91
    }
92
}
93