Producer::publish()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Ccovey\RabbitMQ\Producer;
4
5
use Ccovey\RabbitMQ\ChannelInterface;
6
use Ccovey\RabbitMQ\Connection\ConnectionInterface;
7
use Ccovey\RabbitMQ\QueueDeclarer;
8
9
class Producer implements ProducerInterface
10
{
11
    /**
12
     * @var ConnectionInterface
13
     */
14
    private $connection;
15
16
    /**
17
     * @var QueueDeclarer
18
     */
19
    private $queueDeclarer;
20
21
    /**
22
     * @var ChannelInterface
23
     */
24
    private $channel;
25
26 3
    public function __construct(ConnectionInterface $connection, QueueDeclarer $queueDeclarer, string $channelId = '')
27
    {
28 3
        $this->connection = $connection;
29 3
        $this->queueDeclarer = $queueDeclarer;
30 3
        $this->channel = $this->connection->getChannel($channelId);
31 3
    }
32
33 2
    public function publish(Publishable $message)
34
    {
35 2
        $this->queueDeclarer->declareQueue($message->getQueueName());
36 2
        $this->channel->publish($message);
37 2
    }
38
39 1
    public function getChannel() : ChannelInterface
40
    {
41 1
        return $this->channel;
42
    }
43
}
44