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

SubscriberBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A buildQueue() 0 12 2
A getConnectionManager() 0 4 1
A getQueue() 0 4 1
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