Passed
Push — master ( f54ad3...e9f633 )
by xu
01:54
created

RandomSequenceResolver::sequence()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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 = null;
21
22
    /**
23
     * The sequence.
24
     *
25
     * @var int
26
     */
27
    protected $sequence = 0;
28
29
    /**
30
     *  {@inheritdoc}
31
     */
32 3
    public function sequence(int $currentTime)
33
    {
34 3
        if ($this->lastTimeStamp === $currentTime) {
35 1
            ++$this->sequence;
36 1
            $this->lastTimeStamp = $currentTime;
37
38 1
            return $this->sequence;
39
        }
40
41 3
        $this->sequence = 0;
42 3
        $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 3
        return 0;
45
    }
46
}
47