TestingDatabaseSeeder::createUnconfirmedUsers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
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\CustomDatabaseNotification as Notification;
7
use JobApis\JobsToMail\Models\Search;
8
use JobApis\JobsToMail\Models\Token;
9
10
class TestingDatabaseSeeder extends Seeder
11
{
12
    public function run()
13
    {
14
        $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...
15
        $this->createActiveUsers();
16
        $this->createDeletedUsers();
17
        $this->createUnconfirmedUsers();
18
    }
19
20
    private function createActiveUsers($num = 10)
21
    {
22
        return factory(User::class, $num)
23
            ->states('active')
24
            ->create()
25
            ->each(function(User $user) {
26
                $user->tokens()->save(
27
                    factory(Token::class)->make()
28
                );
29
            })->each(function(User $user) { // Create searches
30
                factory(Search::class, rand(1, 3))->create([
31
                    'user_id' => $user->id
32
                    ])->each(function(Search $search) { // Create notifications
33
                        factory(Notification::class, rand(1, 3))->create([
34
                            'notifiable_id' => $search->user_id,
35
                            'search_id' => $search->id,
36
                        ]);
37
                    });
38
            });
39
    }
40
41
    private function createDeletedUsers($num = 10)
42
    {
43
        return factory(User::class, $num)
44
            ->states('active', 'deleted')
45
            ->create()
46
            ->each(function(User $user) {
47
                $user->tokens()->save(
48
                    factory(Token::class)->make()
49
                );
50
            });
51
    }
52
53
    private function createUnconfirmedUsers($num = 10)
54
    {
55
        return factory(User::class, $num)
56
            ->create()
57
            ->each(function(User $user) {
58
                $user->tokens()->save(
59
                    factory(Token::class)->make()
60
                );
61
            });
62
    }
63
}
64