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.

Driver::countMessages()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.125

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 4
cp 0.5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1.125
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
class Driver implements \Bernard\Driver
11
{
12
    const QUEUE_PREFIX = 'queue:';
13
14
    protected $redis;
15
16
    /**
17
     * @param Redis $redis
18
     */
19 8
    public function __construct(Redis $redis)
20
    {
21 8
        $this->redis = $redis;
22 8
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 2
    public function listQueues()
28
    {
29 2
        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...
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2
    public function createQueue($queueName)
36
    {
37 2
        $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...
38 2
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 2
    public function countMessages($queueName)
44
    {
45 2
        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...
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 2
    public function pushMessage($queueName, $message)
52
    {
53 2
        $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...
54 2
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 1
    public function popMessage($queueName, $duration = 5)
60
    {
61
        // When PhpRedis is set up with an Redis::OPT_PREFIX
62
        // it does set the prefix to the key and to the timeout value something like:
63
        // "BLPOP" "bernard:queue:my-queue" "bernard:5"
64
        //
65
        // To set the resolved key in an array seems fixing this issue. We get:
66
        // "BLPOP" "bernard:queue:my-queue" "5"
67
        //
68
        // see https://github.com/nicolasff/phpredis/issues/158
69 1
        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...
70
71 1
        return [$message, null];
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 2
    public function peekQueue($queueName, $index = 0, $limit = 20)
78
    {
79 2
        $limit += $index - 1;
80
81 2
        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...
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function acknowledgeMessage($queueName, $receipt)
88
    {
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94 2
    public function removeQueue($queueName)
95
    {
96 2
        $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...
97 2
        $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...
98 2
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function info()
104
    {
105
        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...
106
    }
107
108
    /**
109
     * Transform the queueName into a key.
110
     *
111
     * @param string $queueName
112
     *
113
     * @return string
114
     */
115 8
    protected function resolveKey($queueName)
116
    {
117 8
        return self::QUEUE_PREFIX.$queueName;
118
    }
119
}
120