Completed
Pull Request — master (#26)
by Nicolas
02:30
created

PrefixedQueuesClient   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.48%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 7
c 1
b 1
f 0
lcom 1
cbo 2
dl 53
loc 53
ccs 19
cts 21
cp 0.9048
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A publish() 4 4 1
A getQueue() 6 6 1
A getExchange() 4 4 1
A computePrefixedQueueName() 13 13 2
A appendMessageProcessor() 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 Puzzle\AMQP\Clients\Decorators;
4
5
use Puzzle\AMQP\Client;
6
use Puzzle\AMQP\WritableMessage;
7
use Psr\Log\LoggerAwareTrait;
8
use Puzzle\AMQP\Messages\Processor;
9
10 View Code Duplication
class PrefixedQueuesClient implements Client
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...
11
{
12
    const
13
        DELIMITER = '.';
14
15
    use LoggerAwareTrait;
16
17
    private
18
        $client,
19
        $queueNamePrefix;
20
21 5
    public function __construct(Client $client, $queueNamePrefix)
22
    {
23 5
        $this->client = $client;
24 5
        $this->queueNamePrefix = $queueNamePrefix;
25 5
    }
26
27 1
    public function publish($exchangeName, WritableMessage $message)
28
    {
29 1
        return $this->client->publish($exchangeName, $message);
30
    }
31
32 3
    public function getQueue($queueName)
33
    {
34 3
        $prefixedQueueName = $this->computePrefixedQueueName($queueName);
35
36 3
        return $this->client->getQueue($prefixedQueueName);
37
    }
38
39 1
    public function getExchange($exchangeName)
40
    {
41 1
        return $this->client->getExchange($exchangeName);
42
    }
43
44 3
    private function computePrefixedQueueName($queueName)
45
    {
46 3
        $queueNameParts = [];
47
48 3
        if(! empty($this->queueNamePrefix))
49 3
        {
50 2
            $queueNameParts[] = trim($this->queueNamePrefix);
51 2
        }
52
53 3
        $queueNameParts[] = $queueName;
54
55 3
        return implode(self::DELIMITER, $queueNameParts);
56
    }
57
    
58
    public function appendMessageProcessor(Processor $processor)
59
    {
60
        return $this->client->addMessageProcessor($processor);
0 ignored issues
show
Bug introduced by
The method addMessageProcessor() does not seem to exist on object<Puzzle\AMQP\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
    }
62
}
63