Skip to content

Commit 5e8920a

Browse files
committed
amqp lib interop
1 parent a653fa5 commit 5e8920a

5 files changed

Lines changed: 33 additions & 35 deletions

File tree

‎pkg/amqp-lib/AmqpConsumer.php‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function receive($timeout = 0)
147147
*/
148148
public function receiveNoWait()
149149
{
150-
if ($message = $this->channel->basic_get($this->queue->getQueueName(), !!($this->getFlags() & InteropAmqpConsumer::FLAG_NOACK))) {
150+
if ($message = $this->channel->basic_get($this->queue->getQueueName(), (bool) ($this->getFlags() & InteropAmqpConsumer::FLAG_NOACK))) {
151151
return $this->convertMessage($message);
152152
}
153153
}
@@ -232,10 +232,10 @@ private function receiveBasicConsume($timeout)
232232
$consumerTag = $this->channel->basic_consume(
233233
$this->queue->getQueueName(),
234234
$this->getConsumerTag() ?: $this->getQueue()->getConsumerTag(),
235-
!!($this->getFlags() & InteropAmqpConsumer::FLAG_NOLOCAL),
236-
!!($this->getFlags() & InteropAmqpConsumer::FLAG_NOACK),
237-
!!($this->getFlags() & InteropAmqpConsumer::FLAG_EXCLUSIVE),
238-
!!($this->getFlags() & InteropAmqpConsumer::FLAG_NOWAIT),
235+
(bool) ($this->getFlags() & InteropAmqpConsumer::FLAG_NOLOCAL),
236+
(bool) ($this->getFlags() & InteropAmqpConsumer::FLAG_NOACK),
237+
(bool) ($this->getFlags() & InteropAmqpConsumer::FLAG_EXCLUSIVE),
238+
(bool) ($this->getFlags() & InteropAmqpConsumer::FLAG_NOWAIT),
239239
$callback
240240
);
241241

@@ -277,6 +277,7 @@ private function receiveBasicConsume($timeout)
277277
break;
278278
}
279279
}
280-
} catch (AMQPTimeoutException $e) {}
280+
} catch (AMQPTimeoutException $e) {
281+
}
281282
}
282283
}

‎pkg/amqp-lib/AmqpContext.php‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Enqueue\AmqpLib;
44

55
use Interop\Amqp\AmqpBind as InteropAmqpBind;
6+
use Interop\Amqp\AmqpContext as InteropAmqpContext;
67
use Interop\Amqp\AmqpMessage as InteropAmqpMessage;
78
use Interop\Amqp\AmqpQueue as InteropAmqpQueue;
89
use Interop\Amqp\AmqpTopic as InteropAmqpTopic;
9-
use Interop\Amqp\AmqpContext as InteropAmqpContext;
1010
use Interop\Amqp\Impl\AmqpBind;
1111
use Interop\Amqp\Impl\AmqpMessage;
1212
use Interop\Amqp\Impl\AmqpQueue;
@@ -134,11 +134,11 @@ public function declareTopic(InteropAmqpTopic $topic)
134134
$this->getChannel()->exchange_declare(
135135
$topic->getTopicName(),
136136
$topic->getType(),
137-
!!($topic->getFlags() & InteropAmqpTopic::FLAG_PASSIVE),
138-
!!($topic->getFlags() & InteropAmqpTopic::FLAG_DURABLE),
139-
!!($topic->getFlags() & InteropAmqpTopic::FLAG_AUTODELETE),
140-
!!($topic->getFlags() & InteropAmqpTopic::FLAG_INTERNAL),
141-
!!($topic->getFlags() & InteropAmqpTopic::FLAG_NOWAIT),
137+
(bool) ($topic->getFlags() & InteropAmqpTopic::FLAG_PASSIVE),
138+
(bool) ($topic->getFlags() & InteropAmqpTopic::FLAG_DURABLE),
139+
(bool) ($topic->getFlags() & InteropAmqpTopic::FLAG_AUTODELETE),
140+
(bool) ($topic->getFlags() & InteropAmqpTopic::FLAG_INTERNAL),
141+
(bool) ($topic->getFlags() & InteropAmqpTopic::FLAG_NOWAIT),
142142
$topic->getArguments()
143143
);
144144
}
@@ -150,8 +150,8 @@ public function deleteTopic(InteropAmqpTopic $topic)
150150
{
151151
$this->getChannel()->exchange_delete(
152152
$topic->getTopicName(),
153-
!!($topic->getFlags() & InteropAmqpTopic::FLAG_IFUNUSED),
154-
!!($topic->getFlags() & InteropAmqpTopic::FLAG_NOWAIT)
153+
(bool) ($topic->getFlags() & InteropAmqpTopic::FLAG_IFUNUSED),
154+
(bool) ($topic->getFlags() & InteropAmqpTopic::FLAG_NOWAIT)
155155
);
156156
}
157157

@@ -162,11 +162,11 @@ public function declareQueue(InteropAmqpQueue $queue)
162162
{
163163
return $this->getChannel()->queue_declare(
164164
$queue->getQueueName(),
165-
!!($queue->getFlags() & InteropAmqpQueue::FLAG_PASSIVE),
166-
!!($queue->getFlags() & InteropAmqpQueue::FLAG_DURABLE),
167-
!!($queue->getFlags() & InteropAmqpQueue::FLAG_EXCLUSIVE),
168-
!!($queue->getFlags() & InteropAmqpQueue::FLAG_AUTODELETE),
169-
!!($queue->getFlags() & InteropAmqpQueue::FLAG_NOWAIT),
165+
(bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_PASSIVE),
166+
(bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_DURABLE),
167+
(bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_EXCLUSIVE),
168+
(bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_AUTODELETE),
169+
(bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_NOWAIT),
170170
$queue->getArguments()
171171
);
172172
}
@@ -178,9 +178,9 @@ public function deleteQueue(InteropAmqpQueue $queue)
178178
{
179179
$this->getChannel()->queue_delete(
180180
$queue->getQueueName(),
181-
!!($queue->getFlags() & InteropAmqpQueue::FLAG_IFUNUSED),
182-
!!($queue->getFlags() & InteropAmqpQueue::FLAG_IFEMPTY),
183-
!!($queue->getFlags() & InteropAmqpQueue::FLAG_NOWAIT)
181+
(bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_IFUNUSED),
182+
(bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_IFEMPTY),
183+
(bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_NOWAIT)
184184
);
185185
}
186186

@@ -191,7 +191,7 @@ public function purgeQueue(InteropAmqpQueue $queue)
191191
{
192192
$this->getChannel()->queue_purge(
193193
$queue->getQueueName(),
194-
!!($queue->getFlags() & InteropAmqpQueue::FLAG_NOWAIT)
194+
(bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_NOWAIT)
195195
);
196196
}
197197

@@ -210,7 +210,7 @@ public function bind(InteropAmqpBind $bind)
210210
$bind->getTarget()->getTopicName(),
211211
$bind->getSource()->getTopicName(),
212212
$bind->getRoutingKey(),
213-
!!($bind->getFlags() & InteropAmqpBind::FLAG_NOWAIT),
213+
(bool) ($bind->getFlags() & InteropAmqpBind::FLAG_NOWAIT),
214214
$bind->getArguments()
215215
);
216216
// bind queue to exchange
@@ -219,7 +219,7 @@ public function bind(InteropAmqpBind $bind)
219219
$bind->getSource()->getQueueName(),
220220
$bind->getTarget()->getTopicName(),
221221
$bind->getRoutingKey(),
222-
!!($bind->getFlags() & InteropAmqpBind::FLAG_NOWAIT),
222+
(bool) ($bind->getFlags() & InteropAmqpBind::FLAG_NOWAIT),
223223
$bind->getArguments()
224224
);
225225
// bind exchange to queue
@@ -228,7 +228,7 @@ public function bind(InteropAmqpBind $bind)
228228
$bind->getTarget()->getQueueName(),
229229
$bind->getSource()->getTopicName(),
230230
$bind->getRoutingKey(),
231-
!!($bind->getFlags() & InteropAmqpBind::FLAG_NOWAIT),
231+
(bool) ($bind->getFlags() & InteropAmqpBind::FLAG_NOWAIT),
232232
$bind->getArguments()
233233
);
234234
}
@@ -249,7 +249,7 @@ public function unbind(InteropAmqpBind $bind)
249249
$bind->getTarget()->getTopicName(),
250250
$bind->getSource()->getTopicName(),
251251
$bind->getRoutingKey(),
252-
!!($bind->getFlags() & InteropAmqpBind::FLAG_NOWAIT),
252+
(bool) ($bind->getFlags() & InteropAmqpBind::FLAG_NOWAIT),
253253
$bind->getArguments()
254254
);
255255
// bind queue to exchange

‎pkg/amqp-lib/AmqpProducer.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ public function send(PsrDestination $destination, PsrMessage $message)
5656
$amqpMessage,
5757
$destination->getTopicName(),
5858
$message->getRoutingKey(),
59-
!!($message->getFlags() & InteropAmqpMessage::FLAG_MANDATORY),
60-
!!($message->getFlags() & InteropAmqpMessage::FLAG_IMMEDIATE)
59+
(bool) ($message->getFlags() & InteropAmqpMessage::FLAG_MANDATORY),
60+
(bool) ($message->getFlags() & InteropAmqpMessage::FLAG_IMMEDIATE)
6161
);
6262
} else {
6363
$this->channel->basic_publish(
6464
$amqpMessage,
6565
'',
6666
$destination->getQueueName(),
67-
!!($message->getFlags() & InteropAmqpMessage::FLAG_MANDATORY),
68-
!!($message->getFlags() & InteropAmqpMessage::FLAG_IMMEDIATE)
67+
(bool) ($message->getFlags() & InteropAmqpMessage::FLAG_MANDATORY),
68+
(bool) ($message->getFlags() & InteropAmqpMessage::FLAG_IMMEDIATE)
6969
);
7070
}
7171
}

‎pkg/amqp-lib/Tests/AmqpConsumerTest.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,9 @@ public function testShouldCallExpectedMethodsWhenReceiveWithBasicConsumeMethod()
160160
$channel
161161
->expects($this->once())
162162
->method('wait')
163-
->willReturnCallback(function() {
163+
->willReturnCallback(function () {
164164
usleep(2000);
165165
});
166-
;
167166

168167
$consumer = new AmqpConsumer($channel, new AmqpQueue('aName'), new Buffer(), 'basic_consume');
169168

‎pkg/amqp-lib/Tests/AmqpContextTest.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
namespace Enqueue\AmqpLib\Tests;
44

55
use Enqueue\AmqpLib\AmqpContext;
6-
use Enqueue\Null\NullQueue;
76
use Interop\Amqp\Impl\AmqpBind;
87
use Interop\Amqp\Impl\AmqpQueue;
98
use Interop\Amqp\Impl\AmqpTopic;
10-
use Interop\Queue\InvalidDestinationException;
119
use PhpAmqpLib\Channel\AMQPChannel;
1210
use PhpAmqpLib\Connection\AbstractConnection;
1311
use PHPUnit\Framework\TestCase;

0 commit comments

Comments
 (0)