InvoiceLine   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 55
ccs 10
cts 16
cp 0.625
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A invoiceable() 0 3 1
A bill() 0 3 1
A invoice() 0 3 1
A boot() 0 9 2
1
<?php
2
3
namespace NeptuneSoftware\Invoice\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Str;
7
8
class InvoiceLine extends Model
9
{
10
    protected $guarded = [];
11
12
    public $incrementing = false;
13
14
    protected $fillable = [
15
        'amount', 'tax', 'tax_details', 'invoice_id', 'description', 'invoiceable_id',
16
        'invoiceable_type', 'name', 'discount', 'quantity', 'is_free', 'is_complimentary'
17
    ];
18
19
    protected $casts = [
20
        'tax_details' => 'array'
21
    ];
22
23
    /**
24
     * InvoiceLine constructor.
25
     * @param array $attributes
26
     */
27 36
    public function __construct(array $attributes = [])
28
    {
29 36
        parent::__construct($attributes);
30
31 36
        $this->setTable(config('invoice.table_names.invoice_lines'));
32 36
    }
33
34 36
    protected static function boot()
35
    {
36 36
        parent::boot();
37
        static::creating(function ($model) {
38
            /**
39
             * @var \Illuminate\Database\Eloquent\Model $model
40
             */
41 36
            if (!$model->getKey()) {
42 36
                $model->{$model->getKeyName()} = Str::uuid()->toString();
43
            }
44 36
        });
45 36
    }
46
47
    public function invoice()
48
    {
49
        return $this->belongsTo(Invoice::class);
50
    }
51
52
    public function bill()
53
    {
54
        return $this->belongsTo(Bill::class, 'invoice_id');
55
    }
56
57
    /**
58
     * Get the owning invoiceable model.
59
     */
60
    public function invoiceable()
61
    {
62
        return $this->morphTo();
63
    }
64
}
65