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

WorkerBuilder::getQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 4
loc 4
c 1
b 0
f 1
rs 10
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\Connection\Exception\InvalidAMQPChannelException;
7
use Cmobi\RabbitmqBundle\Queue\Queue;
8
use Cmobi\RabbitmqBundle\Queue\QueueBagInterface;
9
use Cmobi\RabbitmqBundle\Queue\QueueBuilderInterface;
10
use Cmobi\RabbitmqBundle\Queue\QueueServiceInterface;
11
use Psr\Log\LoggerInterface;
12
13 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...
14
{
15
    private $queue;
16
    private $connectionManager;
17
    private $logger;
18
19
    public function __construct(ConnectionManager $connManager, LoggerInterface $logger)
20
    {
21
        $this->connectionManager = $connManager;
22
        $this->logger = $logger;
23
        $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...
24
    }
25
26
    /**
27
     * @param $queueName
28
     * @param QueueServiceInterface $queueService
29
     * @param QueueBagInterface $queueBag
30
     * @return Queue
31
     * @throws \Exception
32
     */
33
    public function buildQueue($queueName, QueueServiceInterface $queueService, QueueBagInterface $queueBag)
34
    {
35
        if (! $queueBag instanceof WorkerQueueBag) {
36
            throw new \Exception('Unsupported QueueBag');
37
        }
38
        $queue = new Queue($this->getConnectionManager(), $queueBag, $this->logger);
39
        $queueCallback = new WorkerQueueCallback($queueService);
40
        $queue->setCallback($queueCallback);
41
        $this->queue = $queue;
42
43
        return $queue;
44
    }
45
46
    /**
47
     * @return ConnectionManager
48
     */
49
    public function getConnectionManager()
50
    {
51
        return $this->connectionManager;
52
    }
53
54
    /**
55
     * @return Queue
56
     */
57
    public function getQueue()
58
    {
59
        return $this->queue;
60
    }
61
}
62