Completed
Push — master ( 16758d...149bc6 )
by Karl
15:57 queued 03:39
created

TestingDatabaseSeeder::createActiveUsers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
3
use Faker\Factory as Faker;
4
use Illuminate\Database\Seeder;
5
use JobApis\JobsToMail\Models\User;
6
use JobApis\JobsToMail\Models\Token;
7
use Illuminate\Support\Facades\DB;
8
9
class TestingDatabaseSeeder extends Seeder
10
{
11
    public function run()
12
    {
13
        $this->faker = Faker::create();
0 ignored issues
show
Bug introduced by
The property faker does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
        $this->createActiveUsers();
15
        $this->createDeletedUsers();
16
        $this->createUnconfirmedUsers();
17
    }
18
19
    private function createActiveUsers($num = 10)
20
    {
21
        foreach(range(1, $num) as $index)
22
        {
23
            $user = User::create([
24
                'email' => $this->faker->email(),
25
                'keyword' => $this->faker->word(),
26
                'location' => $this->faker->word().', '.$this->faker->word(),
27
                'confirmed_at' => $this->faker->dateTimeThisYear(),
28
            ]);
29
            Token::create([
30
                'user_id' => $user['id'],
31
                'type' => 'confirm',
32
            ]);
33
        }
34
    }
35
36
    private function createDeletedUsers($num = 10)
37
    {
38
        foreach(range(1, $num) as $index)
39
        {
40
            $user = User::create([
41
                'email' => $this->faker->email(),
42
                'keyword' => $this->faker->word(),
43
                'location' => $this->faker->word().', '.$this->faker->word(),
44
                'confirmed_at' => $this->faker->dateTimeThisYear(),
45
                'deleted_at' => $this->faker->dateTimeThisYear(),
46
            ]);
47
            Token::create([
48
                'user_id' => $user['id'],
49
                'type' => 'confirm',
50
            ]);
51
            Token::create([
52
                'user_id' => $user['id'],
53
                'type' => 'unsubscribe',
54
            ]);
55
        }
56
    }
57
58
    private function createUnconfirmedUsers($num = 10)
59
    {
60
        foreach(range(1, $num) as $index)
61
        {
62
            $user = User::create([
63
                'email' => $this->faker->email(),
64
                'keyword' => $this->faker->word(),
65
                'location' => $this->faker->word().', '.$this->faker->word(),
66
            ]);
67
            Token::create([
68
                'user_id' => $user['id'],
69
                'type' => 'confirm',
70
            ]);
71
        }
72
    }
73
}
74