BaseMapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 53
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
mapMethod() 0 1 ?
mapUrl() 0 1 ?
A mapConfig() 0 7 1
A __construct() 0 4 1
A map() 0 8 1
1
<?php
2
declare(strict_types=1);
3
4
namespace mcorten87\rabbitmq_api\mappers;
5
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 84
    public function __construct(MqManagementConfig $config)
18
    {
19 84
        $this->config = $config;
20 84
    }
21
22
    /**
23
     * @param JobBase $job
24
     * @return MapResult
25
     */
26 68
    public function map(JobBase $job) : MapResult
27
    {
28 68
        return new MapResult(
29 68
            $this->mapMethod(),
30 68
            $this->mapUrl($job),
31 64
            $this->mapConfig($job)
32
        );
33
    }
34
35
    /**
36
     * Created a HTTP method
37
     *
38
     * @return Method
39
     */
40
    abstract protected function mapMethod() : Method;
41
42
    /**
43
     * Determens which url to call
44
     *
45
     * @param JobBase $job
46
     * @return Url
47
     * @throws
48
     */
49
    abstract protected function mapUrl(JobBase $job) : Url ;
50
51
    /**
52
     * Maps the basic config of every API call
53
     *
54
     * @param JobBase $job
55
     * @return array
56
     */
57 64
    protected function mapConfig(JobBase $job) : array
58
    {
59
        return [
60 64
            'auth'      =>  array($this->config->getUser(), $this->config->getPassword()),
61
            'headers'   =>  ['content-type' => 'application/json']
62
        ];
63
    }
64
}
65