Code Duplication    Length = 53-57 lines in 2 locations

src/Clients/Decorators/PrefixedExchangesClient.php 1 location

@@ 10-66 (lines=57) @@
7
use Psr\Log\LoggerAwareTrait;
8
use Puzzle\AMQP\Messages\Processor;
9
10
class PrefixedExchangesClient implements Client
11
{
12
    const
13
        DELIMITER = '.';
14
    
15
    use LoggerAwareTrait;
16
    
17
    private
18
        $client,
19
        $exchangesPrefix;
20
    
21
    public function __construct(Client $client, $exchangesPrefix)
22
    {
23
        $this->client = $client;
24
        $this->exchangesPrefix = $exchangesPrefix;
25
    }
26
    
27
    public function publish($exchangeName, WritableMessage $message)
28
    {
29
        return $this->client->publish(
30
            $this->computeExchangeName($exchangeName),
31
            $message
32
        );
33
    }
34
    
35
    private function computeExchangeName($exchangeName)
36
    {
37
        $exchangeParts = [];
38
        
39
        if(! empty($this->exchangesPrefix))
40
        {
41
            $exchangeParts[] = trim($this->exchangesPrefix);
42
        }
43
44
        $exchangeParts[] = $exchangeName;
45
        
46
        return trim(implode(self::DELIMITER, $exchangeParts));
47
            
48
    }
49
    
50
    public function getQueue($queueName)
51
    {
52
        return $this->client->getQueue($queueName);
53
    }
54
    
55
    public function getExchange($exchangeName)
56
    {
57
        return $this->client->getExchange(
58
            $this->computeExchangeName($exchangeName)
59
        );
60
    }
61
62
    public function appendMessageProcessor(Processor $processor)
63
    {
64
        return $this->client->addMessageProcessor($processor);
65
    }
66
}
67

src/Clients/Decorators/PrefixedQueuesClient.php 1 location

@@ 10-62 (lines=53) @@
7
use Psr\Log\LoggerAwareTrait;
8
use Puzzle\AMQP\Messages\Processor;
9
10
class PrefixedQueuesClient implements Client
11
{
12
    const
13
        DELIMITER = '.';
14
15
    use LoggerAwareTrait;
16
17
    private
18
        $client,
19
        $queueNamePrefix;
20
21
    public function __construct(Client $client, $queueNamePrefix)
22
    {
23
        $this->client = $client;
24
        $this->queueNamePrefix = $queueNamePrefix;
25
    }
26
27
    public function publish($exchangeName, WritableMessage $message)
28
    {
29
        return $this->client->publish($exchangeName, $message);
30
    }
31
32
    public function getQueue($queueName)
33
    {
34
        $prefixedQueueName = $this->computePrefixedQueueName($queueName);
35
36
        return $this->client->getQueue($prefixedQueueName);
37
    }
38
39
    public function getExchange($exchangeName)
40
    {
41
        return $this->client->getExchange($exchangeName);
42
    }
43
44
    private function computePrefixedQueueName($queueName)
45
    {
46
        $queueNameParts = [];
47
48
        if(! empty($this->queueNamePrefix))
49
        {
50
            $queueNameParts[] = trim($this->queueNamePrefix);
51
        }
52
53
        $queueNameParts[] = $queueName;
54
55
        return implode(self::DELIMITER, $queueNameParts);
56
    }
57
    
58
    public function appendMessageProcessor(Processor $processor)
59
    {
60
        return $this->client->addMessageProcessor($processor);
61
    }
62
}
63