JobExchangePublishMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 6
dl 0
loc 50
ccs 17
cts 19
cp 0.8947
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mapMethod() 0 4 1
A mapUrl() 0 12 2
A mapConfig() 0 20 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\JobExchangePublish;
8
use mcorten87\rabbitmq_api\objects\Method;
9
use mcorten87\rabbitmq_api\objects\Url;
10
use mcorten87\rabbitmq_api\services\MqManagementConfig;
11
12
class JobExchangePublishMapper extends BaseMapper
13
{
14
15 2
    protected function mapMethod() : Method
16
    {
17 2
        return new Method(Method::POST);
18
    }
19
20
    /**
21
     * @param JobBase $job
22
     * @return Url
23
     */
24 2
    protected function mapUrl(JobBase $job) : Url
25
    {
26 2
        if (!$job instanceof JobExchangePublish) {
27
            throw new WrongArgumentException($job, JobExchangePublish::class);
28
        }
29
30 2
        $url = 'exchanges';
31 2
        $url .= '/'.urlencode((string)$job->getVirtualHost());
32 2
        $url .= '/'.urlencode((string)$job->getExchangeName());
33 2
        $url .= '/publish';
34 2
        return new Url($url);
35
    }
36
37
    /**
38
     * @param JobBase $job
39
     * @return array
40
     */
41 2
    protected function mapConfig(JobBase $job) : array
42
    {
43 2
        if (!$job instanceof JobExchangePublish) {
44
            throw new WrongArgumentException($job, JobExchangePublish::class);
45
        }
46
47
        $body = [
48 2
            'payload' => (string)$job->getMessage(),
49 2
            'payload_encoding' => 'string', // TODO
50 2
            'routing_key' => (string)$job->getRoutingKey(),
51
            'properties' => [
52 2
                'delivery_mode' =>  $job->getDeliveryMode()->__toInt(),
53
                'headers' => []         // TODO
54
            ]
55
        ];
56
57 2
        return array_merge(parent::mapConfig($job), [
58 2
            'json'      =>  $body,
59
        ]);
60
    }
61
}
62