Completed
Push — master ( cfbf3b...0ff9ac )
by Cody
02:04
created

Channel::basicQos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Ccovey\RabbitMQ;
4
5
use Ccovey\RabbitMQ\Consumer\Consumable;
6
use Ccovey\RabbitMQ\Producer\Publishable;
7
use PhpAmqpLib\Channel\AMQPChannel;
8
9
class Channel implements ChannelInterface
10
{
11
    /**
12
     * @var AMQPChannel
13
     */
14
    private $channel;
15
16 13
    public function __construct(AMQPChannel $channel)
17
    {
18 13
        $this->channel = $channel;
19 13
    }
20
21 1
    public function wait()
22
    {
23 1
        return $this->channel->wait();
24
    }
25
26 1
    public function acknowledge(string $deliveryTag, bool $multiple = false)
27
    {
28 1
        return $this->channel->basic_ack($deliveryTag, $multiple);
29
    }
30
31 3
    public function nack(string $deliveryTag, bool $multiple = false, bool $requeue = false)
32
    {
33 3
        return $this->channel->basic_nack($deliveryTag, $multiple, $requeue);
34
    }
35
36 1
    public function consume(Consumable $consumable) : ChannelInterface
37
    {
38 1
        $this->channel->basic_consume(
39 1
            $consumable->getQueueName(),
40 1
            $consumable->getConsumerTag(),
41 1
            $consumable->isNoLocal(),
42 1
            $consumable->isNoAck(),
43 1
            $consumable->isExclusive(),
44 1
            $consumable->isNoWait(),
45 1
            $consumable->getCallback(),
46 1
            $consumable->getTicket(),
47 1
            $consumable->getArguments()
48
        );
49
50 1
        return $this;
51
    }
52
53 1
    public function publish(Publishable $message) : ChannelInterface
54
    {
55 1
        if ($message->isDelayed()) {
56
            $queue = new Queue($message->getQueueName(), $message->getDelayedExchanged());
57
            $message->setExchange($message->getDelayedExchanged());
0 ignored issues
show
Bug introduced by
The method setExchange() does not seem to exist on object<Ccovey\RabbitMQ\Producer\Publishable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
            $this->bindQueue($queue);
59
        }
60
61 1
        $this->channel->basic_publish(
62 1
            $message->getMessage(),
63 1
            $message->getExchange(),
64 1
            $message->getQueueName(),
65 1
            $message->isMandatory(),
66 1
            $message->isImmediate(),
67 1
            $message->getTicket()
68
        );
69
70 1
        return $this;
71
    }
72
73
    /**
74
     * @param     $prefetchSize
75
     * @param int $prefetchCount
76
     * @param     $aGlobal
77
     *
78
     * @return mixed
79
     */
80 1
    public function basicQos($prefetchSize = null, int $prefetchCount = 1, $aGlobal = null)
81
    {
82 1
        $this->channel->basic_qos($prefetchSize, $prefetchCount, $aGlobal);
83
84 1
        return $this;
85
    }
86
87
    /**
88
     * @param Queue $queue
89
     *
90
     * @return ChannelInterface
91
     */
92 1 View Code Duplication
    public function declareQueue(Queue $queue) : ChannelInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
    {
94 1
        $this->channel->queue_declare(
95 1
            $queue->getQueueName(),
96 1
            $queue->isPassive(),
97 1
            $queue->isDurable(),
98 1
            $queue->isExclusive(),
99 1
            $queue->isAutoDelete(),
100 1
            $queue->isNoWait(),
101 1
            $queue->getArguments(),
0 ignored issues
show
Bug introduced by
It seems like $queue->getArguments() targeting Ccovey\RabbitMQ\Queue::getArguments() can also be of type object<PhpAmqpLib\Wire\AMQPTable>; however, PhpAmqpLib\Channel\AMQPChannel::queue_declare() does only seem to accept array|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
102 1
            $queue->getTicket()
103
        );
104
105 1
        return $this;
106
    }
107
108 1
    public function bindQueue(Queue $queue) : ChannelInterface
109
    {
110 1
        $this->channel->queue_bind(
111 1
            $queue->getQueueName(),
112 1
            $queue->getExchange(),
113 1
            $queue->getQueueName(),
114 1
            $queue->isNoWait(),
115 1
            $queue->getArguments(),
0 ignored issues
show
Bug introduced by
It seems like $queue->getArguments() targeting Ccovey\RabbitMQ\Queue::getArguments() can also be of type object<PhpAmqpLib\Wire\AMQPTable>; however, PhpAmqpLib\Channel\AMQPChannel::queue_bind() does only seem to accept array|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
116 1
            $queue->getTicket()
117
        );
118
119 1
        return $this;
120
    }
121
122 1 View Code Duplication
    public function declareExchange(Exchange $exchange) : ChannelInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
    {
124 1
        $this->channel->exchange_declare(
125 1
            $exchange->getExchange(),
126 1
            $exchange->getType(),
127 1
            $exchange->isPassive(),
128 1
            $exchange->isDurable(),
129 1
            $exchange->isAutoDelete(),
130 1
            $exchange->isInternal(),
131 1
            $exchange->isNoWait(),
132 1
            $exchange->getArguments(),
133 1
            $exchange->getTicket()
134
        );
135
136 1
        return $this;
137
    }
138
139
    /**
140
     * @return array
141
     */
142 1
    public function getCallbacks() : array
143
    {
144 1
        return $this->channel->callbacks;
145
    }
146
147
    public function setCallbacks(array $callbacks = [])
148
    {
149
        $this->channel->callbacks = $callbacks;
150
    }
151
}
152