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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 68
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A enqueue() 0 6 1
A dequeue() 0 8 1
A count() 0 4 1
A updatedLength() 0 8 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