Passed
Pull Request — master (#13)
by Prasit
13:26
created

Invoice::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Soap\Invoices\Models;
4
5
use Illuminate\Support\Str;
6
use Soap\Invoices\InvoiceReferenceGenerator;
7
use Soap\Invoices\Scopes\InvoiceScope;
8
9
class Invoice extends BaseModel
10
{
11
12
    /**
13
     * Invoice constructor.
14
     * @param array $attributes
15
     */
16 24
    public function __construct(array $attributes = [])
17
    {
18 24
        parent::__construct($attributes);
19
20 24
        $this->setTable(config('soap.invoices.table_names.invoices'));
21 24
    }
22
23
    /**
24
     * The "booting" method of the model.
25
     *
26
     * @return void
27
     */
28 24
    protected static function boot()
29
    {
30 24
        parent::boot();
31 24
        static::addGlobalScope(new InvoiceScope());
32 24
        static::creating(function ($model) {
33
            /**
34
             * @var \Illuminate\Database\Eloquent\Model $model
35
             */
36 23
            if (!$model->getKey()) {
37 23
                $model->{$model->getKeyName()} = Str::uuid()->toString();
38
            }
39
40 23
            $model->total     = 0;
41 23
            $model->tax       = 0;
42 23
            $model->discount  = 0;
43 23
            $model->is_bill   = false;
44 23
            $model->currency  = config('soap.invoices.default_currency', 'THB');
45 23
            $model->status    = config('soap.invoices.default_status', 'concept');
46 23
            $model->reference = InvoiceReferenceGenerator::generate();
47 24
        });
48 24
    }
49
}
50