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
Pull Request — master (#234)
by David
02:05
created

PersistentQueue::getReceipt()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Bernard\Queue;
4
5
use Bernard\Driver;
6
use Bernard\Envelope;
7
use Bernard\Serializer;
8
9
/**
10
 * @package Bernard
11
 */
12
class PersistentQueue extends AbstractQueue
13
{
14
    protected $driver;
15
    protected $serializer;
16
    protected $receipts;
17
18
    /**
19
     * @param string     $name
20
     * @param Driver     $driver
21
     * @param Serializer $serializer
22
     */
23
    public function __construct($name, Driver $driver, Serializer $serializer)
24
    {
25
        parent::__construct($name);
26
27
        $this->driver = $driver;
28
        $this->serializer = $serializer;
29
        $this->receipts = new \SplObjectStorage();
30
31
        $this->register();
32
    }
33
34
    /**
35
     * Register with the driver
36
     */
37
    public function register()
38
    {
39
        $this->errorIfClosed();
40
41
        $this->driver->createQueue($this->name);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function count()
48
    {
49
        $this->errorIfClosed();
50
51
        return $this->driver->countMessages($this->name);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function close()
58
    {
59
        parent::close();
60
61
        $this->driver->removeQueue($this->name);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function enqueue(Envelope $envelope)
68
    {
69
        $this->errorIfClosed();
70
71
        $receipt = $this->driver->pushMessage($this->name, $this->serializer->serialize($envelope));
72
73
        if ($receipt) {
74
            $envelope->setReceipt($receipt);
75
            $this->receipts->attach($envelope, $receipt);
76
        }
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function acknowledge(Envelope $envelope)
83
    {
84
        $this->errorIfClosed();
85
86
        if ($this->receipts->contains($envelope)) {
87
            $this->driver->acknowledgeMessage($this->name, $this->receipts[$envelope]);
88
89
            $this->receipts->detach($envelope);
90
        }
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function dequeue()
97
    {
98
        $this->errorIfClosed();
99
100
        list($serialized, $receipt) = $this->driver->popMessage($this->name);
101
102
        if ($serialized) {
103
            $envelope = $this->serializer->unserialize($serialized);
104
105
            $envelope->setReceipt($receipt);
106
            $this->receipts->attach($envelope, $receipt);
107
108
            return $envelope;
109
        }
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function peek($index = 0, $limit = 20)
116
    {
117
        $this->errorIfClosed();
118
119
        $messages = $this->driver->peekQueue($this->name, $index, $limit);
120
121
        return array_map(array($this->serializer, 'unserialize'), $messages);
122
    }
123
124
    /**
125
     * @param Envelope $envelope The envelope.
126
     * @return mixed
127
     */
128
    public function getReceipt(Envelope $envelope)
129
    {
130
        if (!$this->receipts->contains($envelope)) {
131
            return null;
132
        }
133
134
        return $this->receipts->offsetGet($envelope);
135
    }
136
}
137