GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Warehouse   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 93.75%

Importance

Changes 7
Bugs 1 Features 4
Metric Value
wmc 13
c 7
b 1
f 4
lcom 1
cbo 4
dl 0
loc 131
rs 10
ccs 30
cts 32
cp 0.9375

8 Methods

Rating   Name   Duplication   Size   Complexity  
A guitars() 0 4 1
A addRacks() 0 8 2
A addRack() 0 9 2
A racks() 0 4 1
A boot() 0 8 1
A removeRacksNotIn() 0 9 2
A addOrUpdateRacks() 0 8 2
A addOrUpdateRack() 0 7 2
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent;
6
7
/**
8
 * App\Warehouse.
9
 *
10
 * @property int $id
11
 * @property string $name
12
 * @property \Carbon\Carbon $deleted_at
13
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Rack[] $racks
14
 * @method static \Illuminate\Database\Query\Builder|\App\Warehouse whereId($value)
15
 * @method static \Illuminate\Database\Query\Builder|\App\Warehouse whereName($value)
16
 * @method static \Illuminate\Database\Query\Builder|\App\Warehouse whereDeletedAt($value)
17
 * @mixin \Eloquent
18
 */
19
class Warehouse extends Eloquent\Model
20
{
21
    use Eloquent\SoftDeletes;
22
23
    /**
24
     * We do not want any timestamps.
25
     *
26
     * @var bool
27
     */
28
    public $timestamps = false;
29
    /**
30
     * @var array
31
     */
32
    protected $dates = ['deleted_at'];
33
    /**
34
     * The attributes that are mass assignable.
35
     *
36
     * @var array
37
     */
38
    protected $fillable = ['name'];
39
40 13
    public static function boot()
41
    {
42 13
        parent::boot();
43
44 13
        static::deleting(function (Warehouse $warehouse) {
45 2
            $warehouse->racks()->delete();
46 13
        });
47 13
    }
48
49
    /**
50
     * Guitars in the warehouse.
51
     *
52
     * @return Eloquent\Relations\HasManyThrough
53
     */
54
    public function guitars()
55
    {
56
        return $this->hasManyThrough(Guitar::class, Rack::class);
57
    }
58
59
    /**
60
     * Add racks to the warehouse.
61
     *
62
     * @param Eloquent\Collection|array $racks
63
     *
64
     * @return $this
65
     */
66 4
    public function addRacks($racks)
67
    {
68 4
        foreach ($racks as $rack) {
69 3
            $this->addRack($rack);
70
        }
71
72 4
        return $this;
73
    }
74
75
    /**
76
     * Add rack to the warehouse.
77
     *
78
     * @param array|Rack $rack
79
     *
80
     * @return Eloquent\Model
81
     */
82 6
    public function addRack($rack)
83
    {
84 6
        if (is_array($rack)) {
85 3
            $rack = new Rack($rack);
86
        }
87 6
        $this->racks()->save($rack);
88
89 6
        return $this;
90
    }
91
92
    /**
93
     * Racks in the warehouse.
94
     *
95
     * @return Eloquent\Relations\HasMany
96
     */
97 9
    public function racks()
98
    {
99 9
        return $this->hasMany(Rack::class);
100
    }
101
102
    /**
103
     * Remove racks using ids.
104
     *
105
     * @param $ids
106
     *
107
     * @return $this
108
     */
109 2
    public function removeRacksNotIn($ids)
110
    {
111 2
        foreach ($this->racks()->whereNotIn('id', $ids)->get() as $rack) {
112 2
            $rack->guitars()->delete();
113 2
            $rack->delete();
114
        }
115
116 2
        return $this;
117
    }
118
119
    /**
120
     * Add or update the racks.
121
     *
122
     * @param $racks
123
     *
124
     * @return $this
125
     */
126 1
    public function addOrUpdateRacks($racks)
127
    {
128 1
        foreach ($racks as $rack) {
129 1
            $this->addOrUpdateRack($rack);
130
        }
131
132 1
        return $this;
133
    }
134
135
    /**
136
     * Add or Update Racks.
137
     *
138
     * @param $rack
139
     *
140
     * @return $this
141
     */
142 3
    public function addOrUpdateRack($rack)
143
    {
144 3
        (array_has($rack, 'id')) ?
145 3
            $this->racks()->find($rack['id'])->update($rack) : $this->addRack($rack);
146
147 3
        return $this;
148
    }
149
}
150