Passed
Push — chore/add-feature-tests ( 36c2df...e56562 )
by Bas
04:12 queued 19s
created

TaggablesSeeder::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 54
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 54
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\Taggable;
7
8
class TaggablesSeeder extends Seeder
9
{
10
    /**
11
     * Run the database Seeds.
12
     *
13
     * @return void
14
     */
15
    public function run()
16
    {
17
        $taggables = '[
18
           {
19
              "tag_id":"A",
20
              "taggable_id":"winterfell",
21
              "taggable_type":"TestSetup\\\Models\\\Location"
22
           },
23
          {
24
              "tag_id":"S",
25
              "taggable_id":"beyond-the-wall",
26
              "taggable_type":"TestSetup\\\Models\\\Location"
27
           },
28
          {
29
              "tag_id":"E",
30
              "taggable_id":"PetyrBaelish",
31
              "taggable_type":"TestSetup\\\Models\\\Character"
32
           },
33
          {
34
              "tag_id":"F",
35
              "taggable_id":"PetyrBaelish",
36
              "taggable_type":"TestSetup\\\Models\\\Character"
37
           },
38
          {
39
              "tag_id":"G",
40
              "taggable_id":"PetyrBaelish",
41
              "taggable_type":"TestSetup\\\Models\\\Character"
42
           },
43
          {
44
              "tag_id":"A",
45
              "taggable_id":"SandorClegane",
46
              "taggable_type":"TestSetup\\\Models\\\Character"
47
           },
48
          {
49
              "tag_id":"F",
50
              "taggable_id":"SandorClegane",
51
              "taggable_type":"TestSetup\\\Models\\\Character"
52
           },
53
          {
54
              "tag_id":"K",
55
              "taggable_id":"SandorClegane",
56
              "taggable_type":"TestSetup\\\Models\\\Character"
57
           },
58
          {
59
              "tag_id":"P",
60
              "taggable_id":"SandorClegane",
61
              "taggable_type":"TestSetup\\\Models\\\Character"
62
           }
63
        ]';
64
65
        $taggables = json_decode($taggables, 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

65
        $taggables = json_decode($taggables, /** @scrutinizer ignore-type */ JSON_OBJECT_AS_ARRAY);
Loading history...
66
67
        foreach ($taggables as $taggable) {
68
            Taggable::insertOrIgnore($taggable);
69
        }
70
    }
71
}
72