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
Push — master ( 1144b4...828920 )
by Márk
07:09 queued 04:40
created

Driver::peekQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
namespace Bernard\Driver\Interop;
4
5
use Interop\Amqp\AmqpContext;
6
use Interop\Amqp\AmqpQueue;
7
use Interop\Queue\PsrConsumer;
8
use Interop\Queue\PsrContext;
9
10
final class Driver implements \Bernard\Driver
11
{
12
    /**
13
     * @var PsrContext
14
     */
15
    private $context;
16
17
    /**
18
     * @var PsrConsumer[]
19
     */
20
    private $consumers;
21
22
    /**
23
     * @param PsrContext $context
24
     */
25
    public function __construct(PsrContext $context)
26
    {
27
        $this->context = $context;
28
29
        $this->consumers = [];
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function listQueues()
36
    {
37
        return [];
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function createQueue($queueName)
44
    {
45
        if ($this->context instanceof AmqpContext) {
46
            $this->context->declareQueue($this->createAmqpQueue($queueName));
47
        }
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function countMessages($queueName)
54
    {
55
        if ($this->context instanceof AmqpContext) {
56
            return $this->context->declareQueue($this->createAmqpQueue($queueName));
57
        }
58
59
        return 0;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function pushMessage($queueName, $message)
66
    {
67
        $queue = $this->context->createQueue($queueName);
68
        $message = $this->context->createMessage($message);
69
70
        $this->context->createProducer()->send($queue, $message);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function popMessage($queueName, $duration = 5)
77
    {
78
        if ($message = $this->getQueueConsumer($queueName)->receive($duration * 1000)) {
79
            return [$message->getBody(), $message];
80
        }
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function acknowledgeMessage($queueName, $receipt)
87
    {
88
        $this->getQueueConsumer($queueName)->acknowledge($receipt);
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function peekQueue($queueName, $index = 0, $limit = 20)
95
    {
96
        return [];
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function removeQueue($queueName)
103
    {
104
        if ($this->context instanceof AmqpContext) {
105
            $queue = $this->createAmqpQueue($queueName);
106
107
            $this->context->deleteQueue($queue);
108
        }
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    public function info()
115
    {
116
        return [];
117
    }
118
119
    /**
120
     * @param string $queueName
121
     *
122
     * @return PsrConsumer
123
     */
124
    private function getQueueConsumer($queueName)
125
    {
126
        if (false == array_key_exists($queueName, $this->consumers)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
127
            $queue = $this->context->createQueue($queueName);
128
129
            $this->consumers[$queueName] = $this->context->createConsumer($queue);
130
        }
131
132
        return $this->consumers[$queueName];
133
    }
134
135
    /**
136
     * @param string $queueName
137
     *
138
     * @return AmqpQueue
139
     */
140
    private function createAmqpQueue($queueName)
141
    {
142
        /** @var AmqpContext $context */
143
        $context = $this->context;
144
145
        $queue = $context->createQueue($queueName);
146
        $queue->addFlag(AmqpQueue::FLAG_DURABLE);
147
148
        return $queue;
149
    }
150
}
151