Tax::getInfoAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace FeiMx\Tax\Models;
4
5
use FeiMx\Tax\Contracts\TaxContract;
6
use Illuminate\Database\Eloquent\Model;
7
8
class Tax extends Model
9
{
10
    protected $fillable = [
11
        'name', 'type', 'retention',
12
    ];
13
14
    protected $casts = [
15
        'retention' => 'boolean',
16
    ];
17
18
    public function taxGroup()
19
    {
20
        return $this->belongsTo(TaxGroup::class);
21
    }
22
23
    public function info(): TaxContract
24
    {
25
        $className = '\\FeiMx\\Tax\\Taxes\\'.strtoupper($this->name);
26
27
        return new $className($this->retention ? $this->retention : $this->type);
28
    }
29
30
    public function getInfoAttribute(): TaxContract
31
    {
32
        return $this->info();
33
    }
34
35
    public function scopeRetention($query)
36
    {
37
        return $query->whereRetention(true);
38
    }
39
40
    public function scopeTraslate($query)
41
    {
42
        return $query->whereRetention(false);
43
    }
44
}
45