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.

Redis::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\ChildProcess\Pool\Queue;
4
5
use Clue\React\Redis\Client;
6
use React\Promise\FulfilledPromise;
7
use React\Promise\PromiseInterface;
8
use WyriHaximus\React\ChildProcess\Messenger\Messages\Factory;
9
use WyriHaximus\React\ChildProcess\Messenger\Messages\Rpc;
10
use WyriHaximus\React\ChildProcess\Pool\QueueInterface;
11
12
class Redis implements QueueInterface
13
{
14
    /**
15
     * @var Client
16
     */
17
    protected $redis;
18
19
    /**
20
     * @var string
21
     */
22
    protected $key;
23
24
    /**
25
     * @var int
26
     */
27
    protected $length = 0;
28
29
    /**
30
     * Redis constructor.
31
     * @param Client $redis
32
     * @param string $key
33
     */
34 1
    public function __construct(Client $redis, $key)
35
    {
36 1
        $this->redis = $redis;
37 1
        $this->key = $key;
38 1
        $this->updatedLength();
39 1
    }
40
41
    /**
42
     * @param Rpc $rpc
43
     */
44 25
    public function enqueue(Rpc $rpc)
45
    {
46
        return $this->redis->lpush($this->key, \json_encode($rpc))->always(function () {
47 25
            return $this->updatedLength();
48 25
        });
49
    }
50
51
    /**
52
     * @return PromiseInterface
53
     */
54 25
    public function dequeue()
55
    {
56
        return $this->redis->lpop($this->key)->then(function ($rpc) {
57 25
            return \React\Promise\resolve(Factory::fromLine($rpc, []));
58
        })->always(function () {
59 25
            return $this->updatedLength();
60 25
        });
61
    }
62
63
    /**
64
     * @return int
65
     */
66 25
    public function count()
67
    {
68 25
        return $this->length;
69
    }
70
71 26
    protected function updatedLength()
72
    {
73
        return $this->redis->llen($this->key)->then(function ($length) {
74 26
            $this->length = $length;
75
76 26
            return new FulfilledPromise();
77 26
        });
78
    }
79
}
80