Snowflake   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 10
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A boolSnowflake() 0 8 2
1
<?php
2
/**
3
 * 雪花算法 Trait
4
 *
5
 * @author herry@<[email protected]>
6
 * @version 1.0
7
 * @copyright © 2020 MuCTS.com All Rights Reserved.
8
 */
9
10
namespace MuCTS\Laravel\Snowflake\Models\Traits;
11
12
13
use MuCTS\Laravel\Snowflake\Facades\Snowflake as SnowflakeFacade;
14
15
/**
16
 * Trait Snowflake
17
 * @package MuCTS\Laravel\Snowflake\Models\Traits
18
 */
19
trait Snowflake
20
{
21
    protected static function boolSnowflake()
22
    {
23
        static::saving(function ($model) {
24
            if (is_null($model->getKey())) {
25
                $model->setIncrementing(false);
26
                $keyName = $model->getKeyName();
27
                $id = SnowflakeFacade::next();
28
                $model->setAttribute($keyName, $id);
29
            }
30
        });
31
    }
32
}