Completed
Push — master ( 06f519...dbf047 )
by
unknown
02:32
created

FanoutConsumer::createExchange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jellyfish\QueueRabbitMq;
6
7
use Jellyfish\Queue\DestinationInterface;
8
use Jellyfish\Queue\MessageInterface;
9
10
class FanoutConsumer extends AbstractConsumer
11
{
12
    /**
13
     * @param  \Jellyfish\Queue\DestinationInterface  $destination
14
     *
15
     * @return \Jellyfish\Queue\MessageInterface|null
16
     */
17
    public function receiveMessage(DestinationInterface $destination): ?MessageInterface
18
    {
19
        $this->createExchange($destination);
20
        $this->connection->createQueueAndBind($destination);
21
22
        return $this->doReceiveMessage($destination);
23
    }
24
25
    /**
26
     * @param  \Jellyfish\Queue\DestinationInterface  $destination
27
     * @param  int  $limit
28
     *
29
     * @return \Jellyfish\Queue\MessageInterface[]
30
     */
31
    public function receiveMessages(DestinationInterface $destination, int $limit): array
32
    {
33
        $receivedMessages = [];
34
        $this->createExchange($destination);
35
        $this->connection->createQueueAndBind($destination);
36
37
        for ($i = 0; $i < $limit; $i++) {
38
            $receivedMessage = $this->doReceiveMessage($destination);
39
40
            if ($receivedMessage === null) {
41
                return $receivedMessages;
42
            }
43
44
            $receivedMessages[] = $receivedMessage;
45
        }
46
47
        return $receivedMessages;
48
    }
49
50
    /**
51
     * @param  \Jellyfish\Queue\DestinationInterface  $destination
52
     *
53
     * @return void
54
     */
55
    protected function createExchange(DestinationInterface $destination): void
56
    {
57
        $exchange = clone $destination;
58
        $exchange->setName($destination->getProperty('bind'));
0 ignored issues
show
Bug introduced by
It seems like $destination->getProperty('bind') can also be of type null; however, parameter $name of Jellyfish\Queue\DestinationInterface::setName() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

58
        $exchange->setName(/** @scrutinizer ignore-type */ $destination->getProperty('bind'));
Loading history...
59
        $this->connection->createExchange($exchange);
60
    }
61
}
62