Completed
Push — master ( 23e91d...042a18 )
by Cody
02:22
created

Producer::getChannel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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 2
    public function __construct(ConnectionInterface $connection, QueueDeclarer $queueDeclarer, string $channelId = '')
27
    {
28 2
        $this->connection = $connection;
29 2
        $this->queueDeclarer = $queueDeclarer;
30 2
        $this->channel = $this->connection->getChannel($channelId);
31 2
    }
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
    public function getChannel() : ChannelInterface
40
    {
41
        return $this->channel;
42
    }
43
}
44