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

RpcServerBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A buildQueue() 12 12 2
A getConnectionManager() 4 4 1
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\Rpc;
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 RpcServerBuilder 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 RpcQueueBag) {
35
            throw new \Exception('Unsupported QueueBag');
36
        }
37
        $queue = new Queue($this->getConnectionManager(), $queueBag, $this->logger);
38
        $queueCallback = new RpcQueueCallback($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