WorkerBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 1
cbo 2
dl 49
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConnectionManager() 4 4 1
A __construct() 6 6 1
A buildQueue() 12 12 2
A getQueue() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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