Completed
Pull Request — master (#11)
by julian
04:45 queued 01:39
created

PrefixedQueueNameClient::getQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 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 View Code Duplication
class PrefixedQueueNameClient 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...
10
{
11
    const
12
        DELIMITER = '.';
13
14
    use LoggerAwareTrait;
15
16
    private
17
        $client,
1 ignored issue
show
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
        $queueNamePrefix;
19
20 4
    public function __construct(Client $client, $queueNamePrefix)
21
    {
22 4
        $this->client = $client;
23 4
        $this->queueNamePrefix = $queueNamePrefix;
24 4
    }
25
26 1
    public function publish($exchangeName, WritableMessage $message)
27
    {
28 1
        return $this->client->publish($exchangeName, $message);
29
    }
30
31 2
    public function getQueue($queueName)
32
    {
33 2
        $prefixedQueueName = $this->computePrefixedQueueName($queueName);
34
35 2
        return $this->client->getQueue($prefixedQueueName);
36
    }
37
38 1
    public function getExchange($exchangeName)
39
    {
40 1
        return $this->client->getExchange($exchangeName);
41
    }
42
43 2
    private function computePrefixedQueueName($queueName)
44
    {
45 2
        $queueNameParts = [];
46
47 2
        if(! empty($this->queueNamePrefix))
48 2
        {
49 1
            $queueNameParts[] = trim($this->queueNamePrefix);
50 1
        }
51
52 2
        $queueNameParts[] = $queueName;
53
54 2
        return trim(implode(self::DELIMITER, $queueNameParts));
55
    }
56
}
57