Publisher   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 76
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A publish() 0 14 1
A getQueueName() 0 4 1
A getFromName() 0 4 1
A getExchange() 0 4 1
A getExchangeType() 0 4 1
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Transport\Subscriber;
4
5
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPChannel;
6
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPConnectionInterface;
7
use Cmobi\RabbitmqBundle\Connection\ConnectionManager;
8
use Cmobi\RabbitmqBundle\Queue\CmobiAMQPMessage;
9
use Cmobi\RabbitmqBundle\Queue\QueueProducerInterface;
10
11
class Publisher implements QueueProducerInterface
12
{
13
    private $connectionManager;
14
    private $fromName;
15
    private $queueName;
16
    private $exchange;
17
    private $exchangeType;
18
19
    public function __construct(
20
        $exchange,
21
        $exchangeType = ExchangeType::FANOUT,
22
        ConnectionManager $manager,
23
        $fromName,
24
        $queueName = ''
25
    ) {
26
        $this->exchange = $exchange;
27
        $this->exchangeType = $exchangeType;
28
        $this->queueName = $queueName;
29
        $this->fromName = $fromName;
30
        $this->connectionManager = $manager;
31
    }
32
33
    /**
34
     * @param $data
35
     * @param $expire
36
     * @param $priority
37
     */
38
    public function publish($data, $expire = self::DEFAULT_TTL, $priority = self::PRIORITY_LOW)
39
    {
40
41
        /** @var CmobiAMQPConnectionInterface $connection */
42
        $connection = $this->connectionManager->getConnection();
43
        $channel = $connection->channel();
44
        $queueBag = new SubscriberQueueBag($this->getExchange(), $this->getExchangeType(), $this->getQueueName());
45
        $channel->exchangeDeclare($queueBag->getExchangeDeclare());
0 ignored issues
show
Security Bug introduced by
It seems like $queueBag->getExchangeDeclare() targeting Cmobi\RabbitmqBundle\Tra...g::getExchangeDeclare() can also be of type false; however, Cmobi\RabbitmqBundle\Con...nnel::exchangeDeclare() does only seem to accept array, did you maybe forget to handle an error condition?
Loading history...
46
        $msg = new CmobiAMQPMessage((string) $data);
47
        $channel->basic_publish($msg, $queueBag->getExchange());
48
49
        $channel->close();
50
        $connection->close();
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getQueueName()
57
    {
58
        return $this->queueName;
59
    }
60
61
    /**
62
     * Return caller name.
63
     *
64
     * @return string
65
     */
66
    public function getFromName()
67
    {
68
        return $this->fromName;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getExchange()
75
    {
76
        return $this->exchange;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getExchangeType()
83
    {
84
        return $this->exchangeType;
85
    }
86
}
87