GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 1144b4...828920 )
by Márk
07:09 queued 04:40
created

Driver::peekQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
namespace Bernard\Driver\PhpRedis;
4
5
use Redis;
6
7
/**
8
 * Implements a Driver for use with https://github.com/nicolasff/phpredis
9
 *
10
 * @package Bernard
11
 */
12
class Driver implements \Bernard\Driver
13
{
14
    const QUEUE_PREFIX = 'queue:';
15
    
16
    protected $redis;
17
18
    /**
19
     * @param Redis $redis
20
     */
21
    public function __construct(Redis $redis)
22
    {
23
        $this->redis = $redis;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function listQueues()
30
    {
31
        return $this->redis->sMembers('queues');
0 ignored issues
show
Bug introduced by
The method sMembers does only exist in Redis, but not in Predis\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function createQueue($queueName)
38
    {
39
        $this->redis->sAdd('queues', $queueName);
0 ignored issues
show
Bug introduced by
The method sAdd does only exist in Redis, but not in Predis\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function countMessages($queueName)
46
    {
47
        return $this->redis->lLen(self::QUEUE_PREFIX . $queueName);
0 ignored issues
show
Bug introduced by
The method lLen does only exist in Redis, but not in Predis\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function pushMessage($queueName, $message)
54
    {
55
        $this->redis->rpush($this->resolveKey($queueName), $message);
0 ignored issues
show
Bug introduced by
The method rpush does only exist in Redis, but not in Predis\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function popMessage($queueName, $duration = 5)
62
    {
63
        // When PhpRedis is set up with an Redis::OPT_PREFIX
64
        // it does set the prefix to the key and to the timeout value something like:
65
        // "BLPOP" "bernard:queue:my-queue" "bernard:5"
66
        //
67
        // To set the resolved key in an array seems fixing this issue. We get:
68
        // "BLPOP" "bernard:queue:my-queue" "5"
69
        //
70
        // see https://github.com/nicolasff/phpredis/issues/158
71
        list(, $message) = $this->redis->blpop([$this->resolveKey($queueName)], $duration) ?: null;
0 ignored issues
show
Bug introduced by
The method blpop does only exist in Redis, but not in Predis\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
72
73
        return [$message, null];
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function peekQueue($queueName, $index = 0, $limit = 20)
80
    {
81
        $limit += $index - 1;
82
83
        return $this->redis->lRange($this->resolveKey($queueName), $index, $limit);
0 ignored issues
show
Bug introduced by
The method lRange does only exist in Redis, but not in Predis\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function acknowledgeMessage($queueName, $receipt)
90
    {
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function removeQueue($queueName)
97
    {
98
        $this->redis->sRem('queues', $queueName);
0 ignored issues
show
Bug introduced by
The method sRem does only exist in Redis, but not in Predis\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
99
        $this->redis->del($this->resolveKey($queueName));
0 ignored issues
show
Bug introduced by
The method del does only exist in Redis, but not in Predis\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function info()
106
    {
107
        return $this->redis->info();
0 ignored issues
show
Bug introduced by
The method info does only exist in Redis, but not in Predis\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
108
    }
109
110
    /**
111
     * Transform the queueName into a key.
112
     *
113
     * @param string $queueName
114
     *
115
     * @return string
116
     */
117
    protected function resolveKey($queueName)
118
    {
119
        return self::QUEUE_PREFIX . $queueName;
120
    }
121
}
122