Passed
Branch prefix (5b7e30)
by Nicolas
03:33
created

PrefixedExchangesClient::computeExchangeName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 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,
2 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $client.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
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