BlockedItemsTableSeeder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 55 4
1
<?php
2
3
namespace Database\Seeds;
4
5
use Illuminate\Database\Seeder;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Seeder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use jeremykenedy\LaravelBlocker\App\Models\BlockedItem;
7
use jeremykenedy\LaravelBlocker\App\Models\BlockedType;
8
9
class BlockedItemsTableSeeder extends Seeder
10
{
11
    /**
12
     * Run the database seeds.
13
     *
14
     * @return void
15
     */
16
    public function run()
17
    {
18
        /*
19
         * Blocked Types
20
         *
21
         */
22
        $BlockedItems = [
23
            [
24
                'type'  => 'domain',
25
                'value' => 'test.com',
26
                'note'  => 'Block all domains/emails @test.com',
27
            ],
28
            [
29
                'type'  => 'domain',
30
                'value' => 'test.ca',
31
                'note'  => 'Block all domains/emails @test.ca',
32
            ],
33
            [
34
                'type'  => 'domain',
35
                'value' => 'fake.com',
36
                'note'  => 'Block all domains/emails @fake.com',
37
            ],
38
            [
39
                'type'  => 'domain',
40
                'value' => 'example.com',
41
                'note'  => 'Block all domains/emails @example.com',
42
            ],
43
            [
44
                'type'  => 'domain',
45
                'value' => 'mailinator.com',
46
                'note'  => 'Block all domains/emails @mailinator.com',
47
            ],
48
        ];
49
50
        /*
51
         * Add Blocked Items
52
         *
53
         */
54
        if (config('laravelblocker.seedPublishedBlockedItems')) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

54
        if (/** @scrutinizer ignore-call */ config('laravelblocker.seedPublishedBlockedItems')) {
Loading history...
55
            foreach ($BlockedItems as $BlockedItem) {
56
                $blockType = BlockedType::where('slug', $BlockedItem['type'])->first();
57
                $newBlockedItem = BlockedItem::where('typeId', '=', $blockType->id)
58
                    ->where('value', '=', $BlockedItem['value'])
59
                    ->withTrashed()
60
                    ->first();
61
                if ($newBlockedItem === null) {
62
                    $newBlockedItem = BlockedItem::create([
0 ignored issues
show
Unused Code introduced by
The assignment to $newBlockedItem is dead and can be removed.
Loading history...
63
                        'typeId'    => $blockType->id,
64
                        'value'     => $BlockedItem['value'],
65
                        'note'      => $BlockedItem['note'],
66
                    ]);
67
                }
68
            }
69
        }
70
        echo "\e[32mSeeding:\e[0m BlockedItemsTableSeeder\r\n";
71
    }
72
}
73