Test Setup Failed
Push — master ( ac544f...110def )
by xu
01:15
created

LaravelSequenceResolver::sequence()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 1
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
     * @param Redis $redis
0 ignored issues
show
Bug introduced by
There is no parameter named $redis. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
28
     */
29
    public function __construct(Repository $cache)
30
    {
31
        $this->cache = $cache;
32
    }
33
34
    /**
35
     *  {@inheritdoc}
36
     */
37
    public function sequence(int $currentTime)
38
    {
39
        $store = $this->cache->getStore();
40
41
        if ($store instanceof \Illuminate\Cache\RedisStore) {
0 ignored issues
show
Bug introduced by
The class Illuminate\Cache\RedisStore does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
42
            $lua = "return redis.call('exists',KEYS[1])<1 and redis.call('psetex',KEYS[1],ARGV[2],ARGV[1])";
43
            if ($store->connection()->eval($lua, 1, $key = $srore->getPrefix().$currentTime, 1, 1)) {
0 ignored issues
show
Bug introduced by
The variable $srore does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
44
                return $store->connection()->incrby($key, 1);
45
            }
46
        }
47
48
        return (new RandomSequenceResolver())->sequence($currentTime);
49
    }
50
}
51