Test Failed
Push — master ( 9d048f...9d083f )
by Mathijs
07:23
created

JobService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 38
ccs 0
cts 15
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 18 2
1
<?php
2
3
namespace mcorten87\rabbitmq_api\services;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\ClientException;
7
use mcorten87\rabbitmq_api\jobs\JobBase;
8
use mcorten87\rabbitmq_api\MqManagementFactory;
9
use mcorten87\rabbitmq_api\objects\JobResult;
10
11
class JobService
12
{
13
    /** @var MqManagementFactory */
14
    private $factory;
15
16
    /** @var Client */
17
    private $client;
18
19
    public function __construct(MqManagementFactory $factory, Client $client)
20
    {
21
        $this->factory = $factory;
22
        $this->client = $client;
23
    }
24
25
    /**
26
     * @param JobBase $job
27
     * @return JobResult
28
     * @throws \mcorten87\rabbitmq_api\exceptions\NoMapperForJob
29
     */
30
    public function execute(JobBase $job) : JobResult
31
    {
32
        $mapper = $this->factory->getJobMapper($job);
33
34
        $mapResult = $mapper->map($job);
35
36
        try {
37
            $res = $this->client->request(
38
                $mapResult->getMethod(),
39
                $this->factory->getConfig()->getUrl().$mapResult->getUrl(),
40
                $mapResult->getConfig()
41
            );
42
43
            return new JobResult($res);
44
        } catch (ClientException $e) {
45
            return JobResult::populateFromClientException($e);
46
        }
47
    }
48
}
49