Completed
Push — master ( e9401f...2161bf )
by Daniel
03:27
created

SubscriberBuilder::getQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Transport\Subscriber;
4
5
use Cmobi\RabbitmqBundle\Connection\ConnectionManager;
6
use Cmobi\RabbitmqBundle\Queue\Queue;
7
use Cmobi\RabbitmqBundle\Queue\QueueBagInterface;
8
use Cmobi\RabbitmqBundle\Queue\QueueBuilderInterface;
9
use Cmobi\RabbitmqBundle\Queue\QueueServiceInterface;
10
use Psr\Log\LoggerInterface;
11
12
class SubscriberBuilder implements QueueBuilderInterface
13
{
14
    private $queue;
15
    private $connectionManager;
16
    private $connectionName;
17
    private $logger;
18
19
    public function __construct(ConnectionManager $connManager, LoggerInterface $logger, $connectionName = 'default')
20
    {
21
        $this->connectionManager = $connManager;
22
        $this->connectionName = $connectionName;
23
        $this->logger = $logger;
24
        $this->channel = null;
0 ignored issues
show
Bug introduced by
The property channel does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
    }
26
27
    /**
28
     * @param $queueName
29
     * @param QueueServiceInterface $queueService
30
     * @param QueueBagInterface $queueBag
31
     * @return Queue
32
     * @throws \Exception
33
     */
34
    public function buildQueue($queueName, QueueServiceInterface $queueService, QueueBagInterface $queueBag)
35
    {
36
        if (! $queueBag instanceof SubscriberQueueBag) {
37
            throw new \Exception('Unsupported QueueBag');
38
        }
39
        $queue = new Queue($this->getConnectionManager(), $queueBag, $this->logger, $this->connectionName);
40
        $queueCallback = new SubscriberQueueCallback($queueService);
41
        $queue->setCallback($queueCallback);
42
        $this->queue = $queue;
43
44
        return $queue;
45
    }
46
47
    /**
48
     * @return ConnectionManager
49
     */
50
    public function getConnectionManager()
51
    {
52
        return $this->connectionManager;
53
    }
54
55
    /**
56
     * @return Queue
57
     */
58
    public function getQueue()
59
    {
60
        return $this->queue;
61
    }
62
}
63