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

PrefixedExchangesClient   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 2
dl 57
loc 57
ccs 22
cts 24
cp 0.9167
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A publish() 7 7 1
A computeExchangeName() 14 14 2
A getQueue() 4 4 1
A getExchange() 6 6 1
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 PrefixedExchangesClient 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
        $exchangesPrefix;
20
    
21 8
    public function __construct(Client $client, $exchangesPrefix)
22
    {
23 8
        $this->client = $client;
24 8
        $this->exchangesPrefix = $exchangesPrefix;
25 8
    }
26
    
27 6
    public function publish($exchangeName, WritableMessage $message)
28
    {
29 6
        return $this->client->publish(
30 6
            $this->computeExchangeName($exchangeName),
31
            $message
32 6
        );
33
    }
34
    
35 7
    private function computeExchangeName($exchangeName)
36
    {
37 7
        $exchangeParts = [];
38
        
39 7
        if(! empty($this->exchangesPrefix))
40 7
        {
41 5
            $exchangeParts[] = trim($this->exchangesPrefix);
42 5
        }
43
44 7
        $exchangeParts[] = $exchangeName;
45
        
46 7
        return trim(implode(self::DELIMITER, $exchangeParts));
47
            
48
    }
49
    
50 1
    public function getQueue($queueName)
51
    {
52 1
        return $this->client->getQueue($queueName);
53
    }
54
    
55 1
    public function getExchange($exchangeName)
56
    {
57 1
        return $this->client->getExchange(
58 1
            $this->computeExchangeName($exchangeName)
59 1
        );
60
    }
61
62
    public function appendMessageProcessor(Processor $processor)
63
    {
64
        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...
65
    }
66
}
67