DefaultBlockedItemsTableSeeder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 53 3
1
<?php
2
3
namespace jeremykenedy\LaravelBlocker\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 DefaultBlockedItemsTableSeeder 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
        foreach ($BlockedItems as $BlockedItem) {
55
            $blockType = BlockedType::where('slug', $BlockedItem['type'])->first();
56
            $newBlockedItem = BlockedItem::where('typeId', '=', $blockType->id)
57
                ->where('value', '=', $BlockedItem['value'])
58
                ->withTrashed()
59
                ->first();
60
            if ($newBlockedItem === null) {
61
                $newBlockedItem = BlockedItem::create([
0 ignored issues
show
Unused Code introduced by
The assignment to $newBlockedItem is dead and can be removed.
Loading history...
62
                    'typeId'    => $blockType->id,
63
                    'value'     => $BlockedItem['value'],
64
                    'note'      => $BlockedItem['note'],
65
                ]);
66
            }
67
        }
68
        echo "\e[32mSeeding:\e[0m DefaultBlockedItemsTableSeeder\r\n";
69
    }
70
}
71