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

PrefixedExchangesClient::computeExchangeName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
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 addMessageProcessor(Processor $processor)
63
    {
64
        return $this->client->addMessageProcessor($processor);
65
    }
66
}
67