ChildrenSeeder::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 64
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 64
rs 10

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Database\Seeders;
4
5
use Illuminate\Database\Seeder;
6
use TestSetup\Models\Child;
7
8
class ChildrenSeeder extends Seeder
9
{
10
    /**
11
     * Run the database Seeds.
12
     *
13
     * @return void
14
     */
15
    public function run()
16
    {
17
        $children = '[
18
           {
19
              "_from":"characters/NedStark",
20
              "_to":"characters/RobbStark"
21
           },
22
           {
23
              "_from":"characters/NedStark",
24
              "_to":"characters/SansaStark"
25
           },
26
           {
27
              "_from":"characters/NedStark",
28
              "_to":"characters/AryaStark"
29
           },
30
           {
31
              "_from":"characters/NedStark",
32
              "_to":"characters/BranStark"
33
           },
34
           {
35
              "_from":"characters/CatelynStark",
36
              "_to":"characters/RobbStark"
37
           },
38
           {
39
              "_from":"characters/CatelynStark",
40
              "_to":"characters/SansaStark"
41
           },
42
           {
43
              "_from":"characters/CatelynStark",
44
              "_to":"characters/AryaStark"
45
           },
46
           {
47
              "_from":"characters/CatelynStark",
48
              "_to":"characters/BranStark"
49
           },
50
           {
51
              "_from":"characters/NedStark",
52
              "_to":"characters/JonSnow"
53
           },
54
           {
55
              "_from":"characters/TywinLannister",
56
              "_to":"characters/JaimeLannister"
57
           },
58
           {
59
              "_from":"characters/TywinLannister",
60
              "_to":"characters/CerseiLannister"
61
           },
62
           {
63
              "_from":"characters/TywinLannister",
64
              "_to":"characters/TyrionLannister"
65
           },
66
           {
67
              "_from":"characters/CerseiLannister",
68
              "_to":"characters/JoffreyBaratheon"
69
           },
70
           {
71
              "_from":"characters/JaimeLannister",
72
              "_to":"characters/JoffreyBaratheon"
73
           }
74
        ]';
75
76
        $childOf = json_decode($children, 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

76
        $childOf = json_decode($children, /** @scrutinizer ignore-type */ JSON_OBJECT_AS_ARRAY);
Loading history...
77
        foreach ($childOf as $relation) {
78
            Child::insertOrIgnore($relation);
79
        }
80
    }
81
}
82