ExchangeDeclarer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 37
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A declareExchange() 0 7 2
1
<?php
2
3
namespace Ccovey\RabbitMQ;
4
5
use Ccovey\RabbitMQ\Connection\Connection;
6
7
class ExchangeDeclarer
8
{
9
    /**
10
     * @var array
11
     */
12
    private $declaredExchanges = [];
13
14
    /**
15
     * @var Connection
16
     */
17
    private $connection;
18
19
    /**
20
     * @var ChannelInterface
21
     */
22
    private $channel;
23
24 1
    public function __construct(Connection $connection, string $channelId = '')
25
    {
26 1
        $this->connection = $connection;
27 1
        $this->channel = $this->connection->getChannel($channelId);
28 1
    }
29
30
    /*
31
     * This method will be run each time we attempt to queue a message.
32
     * We will cache locally which exchanges we have already declared.
33
     * Declaring an exchange on each iteration of a worker consuming from
34
     * a queue is really slow.
35
     */
36 1
    public function declareExchange(Exchange $exchange)
37
    {
38 1
        if (!in_array($exchange, $this->declaredExchanges)) {
39 1
            $this->channel->declareExchange($exchange);
40 1
            $this->declaredExchanges[] = $exchange;
41
        }
42 1
    }
43
}
44