WorkerBuilder::getConnectionManager()   A
last analyzed

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
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Transport\Worker;
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
11 View Code Duplication
class WorkerBuilder 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...
12
{
13
    private $queue;
14
    private $connectionManager;
15
    private $connectionName;
16
17
    public function __construct(ConnectionManager $connManager, $connectionName = 'default')
18
    {
19
        $this->connectionManager = $connManager;
20
        $this->connectionName = $connectionName;
21
        $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...
22
    }
23
24
    /**
25
     * @param $queueName
26
     * @param QueueServiceInterface $queueService
27
     * @param QueueBagInterface $queueBag
28
     * @return Queue
29
     * @throws \Exception
30
     */
31
    public function buildQueue($queueName, QueueServiceInterface $queueService, QueueBagInterface $queueBag)
32
    {
33
        if (! $queueBag instanceof WorkerQueueBag) {
34
            throw new \Exception('Unsupported QueueBag');
35
        }
36
        $queue = new Queue($this->getConnectionManager(), $queueBag, $this->connectionName);
37
        $queueCallback = new WorkerQueueCallback($queueService);
38
        $queue->setCallback($queueCallback);
39
        $this->queue = $queue;
40
41
        return $queue;
42
    }
43
44
    /**
45
     * @return ConnectionManager
46
     */
47
    public function getConnectionManager()
48
    {
49
        return $this->connectionManager;
50
    }
51
52
    /**
53
     * @return Queue
54
     */
55
    public function getQueue()
56
    {
57
        return $this->queue;
58
    }
59
}
60