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 (#320)
by Maksim
04:24
created

AmqpInteropDriver   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
c 1
b 0
f 0
lcom 2
cbo 2
dl 0
loc 124
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A listQueues() 0 4 1
A createQueue() 0 4 1
A countMessages() 0 4 1
A pushMessage() 0 4 1
A popMessage() 0 4 1
A acknowledgeMessage() 0 4 1
A peekQueue() 0 4 1
A removeQueue() 0 6 1
A info() 0 4 1
A createAmqpQueue() 0 7 1
A getContext() 0 4 1
1
<?php
2
namespace Bernard\Driver;
3
4
use Bernard\Driver;
5
use Interop\Amqp\AmqpContext;
6
use Interop\Amqp\AmqpQueue;
7
8
final class AmqpInteropDriver implements Driver
9
{
10
    /**
11
     * @var AmqpContext
12
     */
13
    private $context;
14
15
    /**
16
     * @var InteropDriver
17
     */
18
    private $interopDriver;
19
20
    /**
21
     * @param InteropDriver $interopDriver
22
     */
23
    public function __construct(InteropDriver $interopDriver)
24
    {
25
        $this->interopDriver = $interopDriver;
26
        $this->context = $interopDriver->getContext();
27
28
        if (false == $this->context instanceof AmqpContext) {
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...
29
            throw new \LogicException(sprintf(
30
                'The context must be instance of "%s" but got "%s"',
31
                AmqpContext::class,
32
                get_class($this->context)
33
            ));
34
        }
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function listQueues()
41
    {
42
        return $this->interopDriver->listQueues();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function createQueue($queueName)
49
    {
50
        $this->context->declareQueue($this->createAmqpQueue($queueName));
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function countMessages($queueName)
57
    {
58
        return $this->context->declareQueue($this->createAmqpQueue($queueName));
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function pushMessage($queueName, $message)
65
    {
66
        $this->interopDriver->pushMessage($queueName, $message);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function popMessage($queueName, $duration = 5)
73
    {
74
        return $this->interopDriver->popMessage($queueName, $duration);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function acknowledgeMessage($queueName, $receipt)
81
    {
82
        $this->interopDriver->acknowledgeMessage($queueName, $receipt);
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function peekQueue($queueName, $index = 0, $limit = 20)
89
    {
90
        return $this->interopDriver->peekQueue($queueName, $index, $limit);
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function removeQueue($queueName)
97
    {
98
        $queue = $this->createAmqpQueue($queueName);
99
100
        $this->context->deleteQueue($queue);
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function info()
107
    {
108
        return $this->interopDriver->info();
109
    }
110
111
    /**
112
     * @param $queueName
113
     *
114
     * @return AmqpQueue
115
     */
116
    private function createAmqpQueue($queueName)
117
    {
118
        $queue = $this->context->createQueue($queueName);
119
        $queue->addFlag(AmqpQueue::FLAG_DURABLE);
120
121
        return $queue;
122
    }
123
124
    /**
125
     * @return AmqpContext
126
     */
127
    public function getContext()
128
    {
129
        return $this->context;
130
    }
131
}
132