Passed
Pull Request — master (#4)
by Nicolas
02:59
created

PrefixedExchangesClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A publish() 0 7 1
A computeExchangeName() 0 14 2
A getQueue() 0 4 1
A getExchange() 0 4 1
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
9
class PrefixedExchangesClient implements Client
10
{
11
    const
12
        DELIMITER = '.';
13
    
14
    use LoggerAwareTrait;
15
    
16
    private
17
        $client,
18
        $exchangesPrefix;
19
    
20
    public function __construct(Client $client, $exchangesPrefix)
21
    {
22
        $this->client = $client;
23
        $this->exchangesPrefix = $exchangesPrefix;
24
    }
25
    
26
    public function publish($exchangeName, WritableMessage $message)
27
    {
28
        return $this->client->publish(
29
            $this->computeExchangeName($exchangeName),
30
            $message
31
        );
32
    }
33
    
34
    private function computeExchangeName($exchangeName)
35
    {
36
        $exchangeParts = [];
37
        
38
        if(! empty($this->exchangesPrefix))
39
        {
40
            $exchangeParts[] = trim($this->exchangesPrefix);
41
        }
42
43
        $exchangeParts[] = $exchangeName;
44
        
45
        return trim(implode(self::DELIMITER, $exchangeParts));
46
            
47
    }
48
    
49
    public function getQueue($queueName)
50
    {
51
        return $this->client->getQueue($queueName);
52
    }
53
    
54
    public function getExchange($exchangeName)
55
    {
56
        return $this->client->getExchange($exchangeName);
57
    }
58
}
59