Completed
Push — master ( daed8a...c138e4 )
by Jorge
01:27
created

Tax::scopeRetention()   A

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 1
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
    public function taxGroup()
15
    {
16
        return $this->belongsTo(TaxGroup::class);
17
    }
18
19
    public function info(): TaxContract
20
    {
21
        $className = '\\FeiMx\\Tax\\Taxes\\'.strtoupper($this->name);
22
23
        return new $className($this->retention);
24
    }
25
26
    public function getInfoAttribute(): TaxContract
27
    {
28
        return $this->info();
29
    }
30
31
    public function scopeRetention($query)
32
    {
33
        return $query->whereRetention(true)->orWhere('name', 'isr');
34
    }
35
36
    public function scopeTraslate($query)
37
    {
38
        return $query->whereRetention(false)->where('name', '<>', 'isr');
39
    }
40
}
41