Passed
Push — next ( fe24b7...3ed8ff )
by Bas
08:01 queued 03:55
created

EventsSeeder::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 39
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 39
rs 10
1
<?php
2
3
namespace Database\Seeders;
4
5
use Illuminate\Database\Seeder;
6
use TestSetup\Models\Event;
7
8
class EventsSeeder extends Seeder
9
{
10
    /**
11
     * Run the database Seeds.
12
     *
13
     * @return void
14
     */
15
    public function run()
16
    {
17
        $events = '[
18
    {
19
        "_key": "first-men-invase-westeros",
20
        "name": "First men invade Westeros",
21
        "type": "invasion",
22
        "age": "The Dawn Age",
23
        "timeline": {
24
            "starts_at": -12000.0,
25
            "ends_at": -10000.0
26
        }
27
    },
28
    {
29
        "_key": "the-long-night",
30
        "name": "The Long Night",
31
        "type": "war",
32
        "age": "The Age of Heroes",
33
        "timeline": {
34
            "starts_at": -8000.0,
35
            "ends_at": -7900.0
36
        }
37
    },
38
    {
39
        "_key": "aegon-the-conqueror-invades-westeros",
40
        "name": "Aegon the Conqueror invades Westeros",
41
        "type": "invasion",
42
        "age": "The Targaryen Conquest",
43
        "timeline": {
44
            "starts_at": -2.0,
45
            "ends_at": 0.0
46
        }
47
    }
48
]';
49
50
        $events = json_decode($events, JSON_OBJECT_AS_ARRAY);
0 ignored issues
show
Bug introduced by
Database\Seeders\JSON_OBJECT_AS_ARRAY of type integer is incompatible with the type boolean|null expected by parameter $associative of json_decode(). ( Ignorable by Annotation )

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

50
        $events = json_decode($events, /** @scrutinizer ignore-type */ JSON_OBJECT_AS_ARRAY);
Loading history...
51
52
        foreach ($events as $event) {
53
            Event::insertOrIgnore($event);
54
        }
55
    }
56
}
57