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.

PersistentQueue   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 78.85%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 108
ccs 41
cts 52
cp 0.7885
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A register() 0 6 1
A count() 0 6 1
A close() 0 6 1
A enqueue() 0 6 1
A acknowledge() 0 10 2
A dequeue() 0 14 2
A peek() 0 8 1
1
<?php
2
3
namespace Bernard\Queue;
4
5
use Bernard\Driver;
6
use Bernard\Envelope;
7
use Bernard\Serializer;
8
9
class PersistentQueue extends AbstractQueue
10
{
11
    protected $driver;
12
    protected $serializer;
13
    protected $receipts;
14
15
    /**
16
     * @param string     $name
17
     * @param Driver     $driver
18
     * @param Serializer $serializer
19
     */
20 19
    public function __construct($name, Driver $driver, Serializer $serializer)
21
    {
22 19
        parent::__construct($name);
23
24 19
        $this->driver = $driver;
25 19
        $this->serializer = $serializer;
26 19
        $this->receipts = new \SplObjectStorage();
27
28 19
        $this->register();
29 19
    }
30
31
    /**
32
     * Register with the driver.
33
     */
34 19
    public function register()
35
    {
36 19
        $this->errorIfClosed();
37
38 19
        $this->driver->createQueue($this->name);
39 19
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function count()
45
    {
46 2
        $this->errorIfClosed();
47
48 1
        return $this->driver->countMessages($this->name);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 7
    public function close()
55
    {
56 7
        parent::close();
57
58 7
        $this->driver->removeQueue($this->name);
59 7
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 2
    public function enqueue(Envelope $envelope)
65
    {
66 2
        $this->errorIfClosed();
67
68 1
        $this->driver->pushMessage($this->name, $this->serializer->serialize($envelope));
69 1
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 3
    public function acknowledge(Envelope $envelope)
75
    {
76 3
        $this->errorIfClosed();
77
78 2
        if ($this->receipts->contains($envelope)) {
79 1
            $this->driver->acknowledgeMessage($this->name, $this->receipts[$envelope]);
80
81 1
            $this->receipts->detach($envelope);
82 1
        }
83 2
    }
84
85
    /**
86
     * {@inheritdoc}
87
     *
88
     * @param int $duration number of seconds to keep polling for messages
89
     */
90 3
    public function dequeue($duration = 5)
91
    {
92 3
        $this->errorIfClosed();
93
94 2
        list($serialized, $receipt) = $this->driver->popMessage($this->name, $duration);
95
96 2
        if ($serialized) {
97 2
            $envelope = $this->serializer->unserialize($serialized);
98
99 2
            $this->receipts->attach($envelope, $receipt);
100
101 2
            return $envelope;
102
        }
103 1
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 5
    public function peek($index = 0, $limit = 20)
109
    {
110 5
        $this->errorIfClosed();
111
112 3
        $messages = $this->driver->peekQueue($this->name, $index, $limit);
113
114 3
        return array_map([$this->serializer, 'unserialize'], $messages);
115
    }
116
}
117