Completed
Push — master ( 74c577...c1ce98 )
by Kirill
06:10
created

IdObserver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 12
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A saving() 0 6 2
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * This file is part of GitterBot package.
5
 *
6
 * @author Serafim <[email protected]>
7
 * @date 28.03.2016 15:52
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
14
namespace Core\Observers;
15
16
use Ramsey\Uuid\Uuid;
17
use Illuminate\Database\Eloquent\Model;
18
19
/**
20
 * Class IdObserver
21
 * @package Core\Observers
22
 */
23
class IdObserver
24
{
25
    /**
26
     * @param Model $model
27
     */
28
    public function saving(Model $model)
29
    {
30
        if (!$model->id) {
31
            $model->id = Uuid::uuid4()->toString();
32
        }
33
    }
34
}
35