Passed
Push — develop ( 9324e6...f3eb57 )
by Septianata
04:31
created

Event::bootEvent()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
cc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Models\Concerns\Order;
4
5
use App\Models\Order;
6
use App\Support\Model\Event as ModelEvent;
7
8
/**
9
 * @see \App\Models\Order
10
 */
11
trait Event
12
{
13
    use ModelEvent;
14
15
    /**
16
     * Boot the trait on the model.
17
     *
18
     * @return void
19
     */
20 5
    protected static function bootEvent()
21
    {
22 5
        static::creating(function (Order $model) {
23 3
            if (is_null($model->code)) {
0 ignored issues
show
introduced by
The condition is_null($model->code) is always false.
Loading history...
24 3
                $model->code = $model->generateCode();
25
            }
26 5
        });
27
28 5
        static::deleting(function (Order $model) {
29 2
            $model->items->map->delete();
30 5
        });
31 5
    }
32
}
33