Completed
Push — master ( c432ac...8e117f )
by Mathijs
04:01
created

BaseMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A map() 0 7 1
mapMethod() 0 1 ?
mapUrl() 0 1 ?
A mapConfig() 0 6 1
1
<?php
2
3
namespace mcorten87\rabbitmq_api\mappers;
4
5
use GuzzleHttp\Client;
6
use mcorten87\rabbitmq_api\jobs\JobBase;
7
use mcorten87\rabbitmq_api\MqManagementConfig;
8
use mcorten87\rabbitmq_api\objects\MapResult;
9
use mcorten87\rabbitmq_api\objects\Method;
10
use mcorten87\rabbitmq_api\objects\Url;
11
12
abstract class BaseMapper
13
{
14
    /** @var MqManagementConfig */
15
    protected $config;
16
17
    public function __construct(MqManagementConfig $config)
18
    {
19
        $this->config = $config;
20
    }
21
22
    /**
23
     * @param JobBase $job
24
     * @return MapResult
25
     */
26
    public function map(JobBase $job) : MapResult {
27
        return new MapResult(
28
            $this->mapMethod($job),
29
            $this->mapUrl($job),
30
            $this->mapConfig($job)
31
        );
32
    }
33
34
    abstract protected function mapMethod(JobBase $job) : Method;
35
36
    abstract protected function mapUrl(JobBase $job) : Url;
37
38
    protected function mapConfig(JobBase $job) : array {
39
        return [
40
            'auth'      =>  array($this->config->getUser(), $this->config->getPassword()),
41
            'headers'   =>  ['content-type' => 'application/json'],
42
        ];
43
    }
44
}
45