JobBindingToExchangeCreateMapper::mapMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
namespace mcorten87\rabbitmq_api\mappers;
4
5
use mcorten87\rabbitmq_api\exceptions\WrongArgumentException;
6
use mcorten87\rabbitmq_api\jobs\JobBase;
7
use mcorten87\rabbitmq_api\jobs\JobBindingToExchangeCreate;
8
use mcorten87\rabbitmq_api\objects\Method;
9
use mcorten87\rabbitmq_api\objects\Url;
10
11 View Code Duplication
class JobBindingToExchangeCreateMapper 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...
12
{
13
    protected function mapMethod() : Method
14
    {
15
        return new Method(Method::POST);
16
    }
17
18
    /**
19
     * @param JobBase $job
20
     * @return Url
21
     * @throws WrongArgumentException
22
     */
23
    protected function mapUrl(JobBase $job) : Url
24
    {
25
        if (!$job instanceof JobBindingToExchangeCreate) {
26
            throw new WrongArgumentException($job, JobBindingToExchangeCreate::class);
27
        }
28
29
        return new Url('bindings/'
30
            .urlencode((string)$job->getVirtualHost()).'/'
31
            .'e/'
32
            .urlencode((string)$job->getExchangeName()).'/'
33
            .$job->getDestinationType().'/'
34
            .urlencode((string)$job->getToExchange()));
35
    }
36
37
    /**
38
     * @param JobBase $job
39
     * @return array
40
     * @throws WrongArgumentException
41
     */
42
    protected function mapConfig(JobBase $job) : array
43
    {
44
        if (!$job instanceof JobBindingToExchangeCreate) {
45
            throw new WrongArgumentException($job, JobBindingToExchangeCreate::class);
46
        }
47
48
        $body = [
49
            'arguments'         => [],
50
            'destination'       => (string)$job->getToExchange(),
51
            'destination_type'  => $job->getDestinationType(),
52
            'routing_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