Passed
Pull Request — master (#12)
by julian
03:55
created

PrefixedQueuesClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
c 1
b 1
f 0
lcom 1
cbo 2
dl 48
loc 48
ccs 19
cts 19
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A publish() 4 4 1
A getQueue() 6 6 1
A getExchange() 4 4 1
A computePrefixedQueueName() 13 13 2

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
9 View Code Duplication
class PrefixedQueuesClient 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 5
    public function __construct(Client $client, $queueNamePrefix)
21
    {
22 5
        $this->client = $client;
23 5
        $this->queueNamePrefix = $queueNamePrefix;
24 5
    }
25
26 1
    public function publish($exchangeName, WritableMessage $message)
27
    {
28 1
        return $this->client->publish($exchangeName, $message);
29
    }
30
31 3
    public function getQueue($queueName)
32
    {
33 3
        $prefixedQueueName = $this->computePrefixedQueueName($queueName);
34
35 3
        return $this->client->getQueue($prefixedQueueName);
36
    }
37
38 1
    public function getExchange($exchangeName)
39
    {
40 1
        return $this->client->getExchange($exchangeName);
41
    }
42
43 3
    private function computePrefixedQueueName($queueName)
44
    {
45 3
        $queueNameParts = [];
46
47 3
        if(! empty($this->queueNamePrefix))
48 3
        {
49 2
            $queueNameParts[] = trim($this->queueNamePrefix);
50 2
        }
51
52 3
        $queueNameParts[] = $queueName;
53
54 3
        return implode(self::DELIMITER, $queueNameParts);
55
    }
56
}
57