RandomSequenceResolver   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A sequence() 0 14 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
class RandomSequenceResolver implements SequenceResolver
14
{
15
    /**
16
     * The las ttimestamp.
17
     *
18
     * @var null
19
     */
20
    protected $lastTimeStamp = -1;
21
22
    /**
23
     * The sequence.
24
     *
25
     * @var int
26
     */
27
    protected $sequence = 0;
28
29
    /**
30
     *  {@inheritdoc}
31
     */
32 7
    public function sequence(int $currentTime)
33
    {
34 7
        if ($this->lastTimeStamp === $currentTime) {
35 4
            ++$this->sequence;
36 4
            $this->lastTimeStamp = $currentTime;
37
38 4
            return $this->sequence;
39
        }
40
41 7
        $this->sequence = 0;
42 7
        $this->lastTimeStamp = $currentTime;
0 ignored issues
show
Documentation Bug introduced by
It seems like $currentTime of type integer is incompatible with the declared type null of property $lastTimeStamp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
44 7
        return 0;
45
    }
46
}
47