TaxGroup::activate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace FeiMx\Tax\Models;
4
5
use FeiMx\Tax\TaxManager;
6
use Illuminate\Database\Eloquent\Model;
7
8
class TaxGroup extends Model
9
{
10
    protected $fillable = [
11
        'name', 'active',
12
    ];
13
14
    public function taxes()
15
    {
16
        return $this->hasMany(Tax::class);
17
    }
18
19
    public function addTax(Tax $tax)
20
    {
21
        $this->taxes()->save($tax);
22
    }
23
24
    public function removeTax(Tax $tax)
25
    {
26
        $this->taxes()->find($tax->id)->delete();
27
    }
28
29
    public function hasTax(Tax $tax)
30
    {
31
        return (bool) $this->taxes()->find($tax->id);
32
    }
33
34
    public function deactivate()
35
    {
36
        $this->active = false;
37
        $this->save();
38
    }
39
40
    public function activate()
41
    {
42
        $this->active = true;
43
        $this->save();
44
    }
45
46
    public function scopeActive($query, $active = true)
47
    {
48
        return $query->whereActive($active);
49
    }
50
51
    public function taxManager($amount = 100)
52
    {
53
        return new TaxManager($amount);
54
    }
55
}
56