Completed
Push — dev-master ( 83e592...d1cf50 )
by Vijay
03:14 queued 12s
created

UserSeeder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 4
lcom 0
cbo 3
1
<?php
2
3
use Phinx\Seed\AbstractSeed;
4
5
class UserSeeder extends AbstractSeed
6
{
7
8
    public function run()
9
    {
10
        $faker = Faker\Factory::create();
11
        $data = [];
12
        $flush = 32;
13
        $max = 512;
14
        $statuses = [
15
            'suspended', // we closed account
16
            'closed', // we closed account
17
            'cancelled', // user cancelled account
18
            'registered', // initial registration
19
            'confirmed', // user has confirmed email address - needed for api access
20
        ];
21
        $groups = ['admin', 'user', 'api', 'user,api', 'admin,user,api'];
22
        for ($i = 0; $i < $max; $i++) {
23
            $data[] = [
24
                'uuid' => $faker->uuid,
25
                'password' => substr(sha1($faker->password),0,15),
26
                'email' => $faker->email,
27
                'firstname' => $faker->firstName,
28
                'lastname' => $faker->lastName,
29
                'groups' => $groups[rand(0,4)],
30
                'status' => $statuses[rand(0,4)],
31
                'password_question' => $faker->sentence(10, true),
32
                'password_answer' => $faker->sentence(3),
33
                'created' => $faker->dateTimeBetween('-3 years', 'now')->format('Y-m-d H:i:s'),
34
                'login_last' => $faker->dateTimeBetween('-3 years', 'now')->format('Y-m-d H:i:s'),
35
                'login_count' => rand(1, 1000)
36
            ];
37
            // flush data to database
38
            if (count($data) > $flush) {
39
                $this->insert('users', $data);
40
                $data = [];
41
            }
42
        }
43
        if (count($data) > $flush) {
44
            $this->insert('users', $data);
45
            $data = [];
46
        }
47
    }
48
49
}
50