Passed
Pull Request — master (#17)
by Stephen
06:55
created

DatabaseSeeder::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 18
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 26
rs 9.6666
1
<?php
2
3
namespace Database\Seeders;
4
5
use Database\Factories\RoleFactory;
6
use Illuminate\Database\Seeder;
7
use Sfneal\Users\Models\Role;
8
use Sfneal\Users\Models\Team;
9
use Sfneal\Users\Models\User;
10
use Sfneal\Users\Models\UserNotification;
11
12
class DatabaseSeeder extends Seeder
13
{
14
    /**
15
     * Run the database seeds.
16
     *
17
     * @return void
18
     */
19
    public function run()
20
    {
21
        foreach (RoleFactory::NAMES as $roleName) {
22
            Role::factory()
23
                ->has(User::factory()->count(20), 'users')
24
                ->create([
25
                    'type' => 'user',
26
                    'name' => $roleName,
27
                ]);
28
        }
29
30
        User::query()
31
            ->limit(User::query()->count() / 2)
0 ignored issues
show
Bug introduced by
The method limit() does not exist on Sfneal\Users\Builders\UserBuilder. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
            ->/** @scrutinizer ignore-call */ limit(User::query()->count() / 2)
Loading history...
Bug introduced by
The method count() does not exist on Sfneal\Users\Builders\UserBuilder. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
            ->limit(User::query()->/** @scrutinizer ignore-call */ count() / 2)
Loading history...
32
            ->get()
33
            ->each(function (User $user) {
34
                Team::factory()
35
                    ->create([
36
                        'user_id' => $user->getKey()
37
                    ]);
38
            });
39
40
        User::all()->each(function (User $user) {
41
            UserNotification::factory()
42
                ->count(3)
43
                ->create([
44
                    'user_id' => $user->getKey()
45
                ]);
46
        });
47
    }
48
}
49