Passed
Branch master (f937f1)
by Burak
05:52
created

HasUUID   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 35
ccs 10
cts 10
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getKeyType() 0 3 1
A getIncrementing() 0 3 1
A bootHasUUID() 0 8 2
1
<?php
2
3
namespace App\Traits;
4
5
use Illuminate\Support\Str;
6
7
trait HasUUID
8
{
9
    /**
10
     * Boot model class.
11
     */
12 18
    protected static function bootHasUUID()
13
    {
14 18
        static::creating(function ($model) {
15
            /*
16
             * @var \Illuminate\Database\Eloquent\Model
17
             */
18 16
            if (! $model->getKey()) {
19 16
                $model->{$model->getKeyName()} = Str::uuid()->toString();
20
            }
21 18
        });
22 18
    }
23
24
    /**
25
     * Do not increment primary key.
26
     *
27
     * @return bool
28
     */
29 16
    public function getIncrementing()
30
    {
31 16
        return false;
32
    }
33
34
    /**
35
     * Return primary key type.
36
     *
37
     * @return string
38
     */
39 12
    public function getKeyType()
40
    {
41 12
        return 'string';
42
    }
43
}
44