Completed
Push — master ( bb02de...9def54 )
by Daniel
11:27
created

SubscriberBuilder::getQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Transport\PubSub;
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 View Code Duplication
class SubscriberBuilder implements QueueBuilderInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    private $queue;
15
    private $connectionManager;
16
    private $logger;
17
18
    public function __construct(ConnectionManager $connManager, LoggerInterface $logger)
19
    {
20
        $this->connectionManager = $connManager;
21
        $this->logger = $logger;
22
        $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...
23
    }
24
25
    /**
26
     * @param $queueName
27
     * @param QueueServiceInterface $queueService
28
     * @param QueueBagInterface $queueBag
29
     * @return Queue
30
     * @throws \Exception
31
     */
32
    public function buildQueue($queueName, QueueServiceInterface $queueService, QueueBagInterface $queueBag)
33
    {
34
        if (! $queueBag instanceof SubscriberQueueBag) {
35
            throw new \Exception('Unsupported QueueBag');
36
        }
37
        $queue = new Queue($this->getConnectionManager(), $queueBag, $this->logger);
38
        $queueCallback = new SubscriberQueueCallback($queueService);
39
        $queue->setCallback($queueCallback);
40
        $this->queue = $queue;
41
42
        return $queue;
43
    }
44
45
    /**
46
     * @return ConnectionManager
47
     */
48
    public function getConnectionManager()
49
    {
50
        return $this->connectionManager;
51
    }
52
53
    /**
54
     * @return Queue
55
     */
56
    public function getQueue()
57
    {
58
        return $this->queue;
59
    }
60
}
61