JobExchangeCreateMapper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 6
dl 0
loc 51
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mapMethod() 0 4 1
A mapConfig() 0 20 3
A mapUrl() 0 12 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\JobExchangeCreate;
8
use mcorten87\rabbitmq_api\objects\Method;
9
use mcorten87\rabbitmq_api\objects\Url;
10
11
class JobExchangeCreateMapper extends BaseMapper
12
{
13 4
    protected function mapMethod() : Method
14
    {
15 4
        return new Method(Method::PUT);
16
    }
17
18
    /**
19
     * @param JobBase $job
20
     * @return Url
21
     * @throws WrongArgumentException
22
     */
23 4
    protected function mapUrl(JobBase $job) : Url
24
    {
25 4
        if (!$job instanceof JobExchangeCreate) {
26 1
            throw new WrongArgumentException($job, JobExchangeCreate::class);
27
        }
28
29 3
        return new Url(
30
            'exchanges/'
31 3
            .urlencode((string)$job->getVirtualHost())
32 3
            .'/'.urlencode((string)$job->getExchangeName())
33
        );
34
    }
35
36
    /**
37
     * @param JobBase $job
38
     * @return array
39
     * @throws WrongArgumentException
40
     */
41 3
    protected function mapConfig(JobBase $job) : array
42
    {
43 3
        if (!$job instanceof JobExchangeCreate) {
44
            throw new WrongArgumentException($job, JobExchangeCreate::class);
45
        }
46
47
        $body = [
48 3
            'auto_delete'   => $job->isAutoDelete(),
49 3
            'durable'       => $job->isDurable(),
50
            'arguments'     => []
51
        ];
52
53 3
        foreach ($job->getArguments() as $argument) {
54 1
            $body['arguments'][$argument->getArgumentName()] = $argument->getValue();
55
        };
56
57 3
        return array_merge(parent::mapConfig($job), [
58 3
            'json'      =>  $body,
59
        ]);
60
    }
61
}
62