Completed
Push — dev-master ( 50729f...83e592 )
by Vijay
04:16
created

UserSeeder::run()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 40
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 32
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 40
rs 8.5806
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 = [];
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
46
        }
47
    }
48
49
}
50