JobBindingToExchangeDeleteMapper::mapConfig()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 1
crap 6
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\JobBindingToExchangeDelete;
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 JobBindingToExchangeDeleteMapper 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
    protected function mapMethod() : Method
16
    {
17
        return new Method(Method::DELETE);
18
    }
19
20
    /**
21
     * @param JobBindingToExchangeDelete $job
22
     * @return Url
23
     */
24
    protected function mapUrl(JobBase $job) : Url
25
    {
26
        if (!$job instanceof JobBindingToExchangeDelete) {
27
            throw new WrongArgumentException($job, JobBindingToExchangeDelete::class);
28
        }
29
30
        return new Url('bindings/'
31
            .urlencode((string)$job->getVirtualHost()).'/'
32
            .'e/'
33
            .urlencode((string)$job->getExchangeName()).'/'
34
            .$job->getDestinationType().'/'
35
            .urlencode((string)$job->getToExchange())
36
            .'/'.(!empty((string) $job->getRoutingKey()) ? (string) $job->getRoutingKey() : '~')
37
        );
38
    }
39
40
    /**
41
     * @param JobBindingToExchangeDelete $job
42
     * @return array
43
     */
44
    protected function mapConfig(JobBase $job) : array {
45
        if (!$job instanceof JobBindingToExchangeDelete) {
46
            throw new WrongArgumentException($job, JobBindingToExchangeDelete::class);
47
        }
48
49
        $body = [
50
            'destination'       => (string)$job->getToExchange(),
51
            'destination_type'  => $job->getDestinationType(),
52
            'properties_key'       => (string)$job->getRoutingKey(),
53
            'source'            => (string)$job->getExchangeName(),
54
            'vhost'             => $job->getVirtualHost(),
55
        ];
56
57
        return array_merge(parent::mapConfig($job), [
58
            'json'      =>  $body,
59
        ]);
60
    }
61
}
62