LaravelSequenceResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 31
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sequence() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the godruoyi/php-snowflake.
5
 *
6
 * (c) Godruoyi <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled.
9
 */
10
11
namespace Godruoyi\Snowflake;
12
13
use Illuminate\Contracts\Cache\Repository;
14
15
class LaravelSequenceResolver implements SequenceResolver
16
{
17
    /**
18
     * The laravel cache instance.
19
     *
20
     * @var \Illuminate\Contracts\Cache\Repository
21
     */
22
    protected $cache;
23
24
    /**
25
     * Init resolve instance, must connectioned.
26
     */
27
    public function __construct(Repository $cache)
28
    {
29
        $this->cache = $cache;
30
    }
31
32
    /**
33
     *  {@inheritdoc}
34
     */
35
    public function sequence(int $currentTime)
36
    {
37
        $key = $currentTime;
38
39
        if ($this->cache->add($key, 1, 1)) {
40
            return 0;
41
        }
42
43
        return $this->cache->increment($key, 1);
44
    }
45
}
46