Cart   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
A items() 0 4 1
1
<?php
2
3
namespace Treestoneit\ShoppingCart\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
/**
8
 * App\Cart\Models\Cart.
9
 *
10
 * @property int $id
11
 * @property int|null $user_id
12
 * @property \Illuminate\Support\Carbon|null $created_at
13
 * @property \Illuminate\Support\Carbon|null $updated_at
14
 * @property-read \Treestoneit\ShoppingCart\Models\CartItemCollection|\Treestoneit\ShoppingCart\Models\CartItem[] $items
15
 * @property-read int|null $items_count
16
 * @method static \Illuminate\Database\Eloquent\Builder|\Treestoneit\ShoppingCart\Models\Cart newModelQuery()
17
 * @method static \Illuminate\Database\Eloquent\Builder|\Treestoneit\ShoppingCart\Models\Cart newQuery()
18
 * @method static \Illuminate\Database\Eloquent\Builder|\Treestoneit\ShoppingCart\Models\Cart query()
19
 * @method static \Illuminate\Database\Eloquent\Builder|\Treestoneit\ShoppingCart\Models\Cart whereCreatedAt($value)
20
 * @method static \Illuminate\Database\Eloquent\Builder|\Treestoneit\ShoppingCart\Models\Cart whereId($value)
21
 * @method static \Illuminate\Database\Eloquent\Builder|\Treestoneit\ShoppingCart\Models\Cart whereUpdatedAt($value)
22
 * @method static \Illuminate\Database\Eloquent\Builder|\Treestoneit\ShoppingCart\Models\Cart whereUserId($value)
23
 * @mixin \Eloquent
24
 */
25
class Cart extends Model
26
{
27
    /**
28
     * The attributes that aren't mass assignable.
29
     *
30
     * @var array
31
     */
32
    protected $guarded = ['id'];
33
34
    /**
35
     * Add a deleting listener to delete all items.
36
     *
37
     * @return void
38
     */
39
    protected static function boot()
40
    {
41
        parent::boot();
42
43
        static::deleting(function (self $cart) {
44
            return $cart->items()->delete();
45
        });
46
    }
47
48
    /**
49
     * The items in this cart instance.
50
     *
51
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
52
     */
53
    public function items()
54
    {
55
        return $this->hasMany(CartItem::class);
56
    }
57
}
58