JobBindingToQueueDeleteMapper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 91.3%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 5
dl 52
loc 52
ccs 21
cts 23
cp 0.913
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mapMethod() 4 4 1
A mapUrl() 16 16 3
A mapConfig() 19 19 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
declare(strict_types=1);
3
namespace mcorten87\rabbitmq_api\mappers;
4
5
6
use mcorten87\rabbitmq_api\exceptions\WrongArgumentException;
7
use mcorten87\rabbitmq_api\jobs\JobBase;
8
use mcorten87\rabbitmq_api\jobs\JobBindingToQueueDelete;
9
use mcorten87\rabbitmq_api\objects\Method;
10
use mcorten87\rabbitmq_api\objects\Url;
11
use mcorten87\rabbitmq_api\services\MqManagementConfig;
12
13 View Code Duplication
class JobBindingToQueueDeleteMapper extends BaseMapper
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...
14
{
15 1
    protected function mapMethod() : Method
16
    {
17 1
        return new Method(Method::DELETE);
18
    }
19
20
    /**
21
     * @param JobBindingToQueueDelete $job
22
     * @return Url
23
     */
24 1
    protected function mapUrl(JobBase $job) : Url
25
    {
26 1
        if (!$job instanceof JobBindingToQueueDelete) {
27
            throw new WrongArgumentException($job, JobBindingToQueueDelete::class);
28
        }
29
30
31 1
        return new Url('bindings/'
32 1
            .urlencode((string)$job->getVirtualHost()).'/'
33 1
            .'e/'
34 1
            .urlencode((string)$job->getExchangeName()).'/'
35 1
            .$job->getDestinationType().'/'
36 1
            .urlencode((string)$job->getQueueName())
37 1
            .'/'.(!empty((string) $job->getRoutingKey()) ? (string) $job->getRoutingKey() : '~')
38
        );
39
    }
40
41
    /**
42
     * @param JobBindingToQueueDelete $job
43
     * @return array
44
     */
45 1
    protected function mapConfig(JobBase $job) : array {
46 1
        if (!$job instanceof JobBindingToQueueDelete) {
47
            throw new WrongArgumentException($job, JobBindingToQueueDelete::class);
48
        }
49
50
51
        $body = [
52 1
            'arguments'         => [],
53 1
            'destination'       => (string)$job->getQueueName(),
54 1
            'destination_type'  => $job->getDestinationType(),
55 1
            'routing_key'       => (string)$job->getRoutingKey(),
56 1
            'source'            => (string)$job->getExchangeName(),
57 1
            'vhost'             => $job->getVirtualHost(),
58
        ];
59
60 1
        return array_merge(parent::mapConfig($job), [
61 1
            'json'      =>  $body,
62
        ]);
63
    }
64
}
65