Response   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
c 3
b 1
f 0
lcom 1
cbo 3
dl 0
loc 47
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A promise() 0 4 1
A getBody() 0 14 3
1
<?php
2
3
namespace Raidros\Storer;
4
5
use GuzzleHttp\Psr7\Response as Psr7Response;
6
use Raidros\Storer\Exception\ResponseWithoutBody;
7
8
class Response
9
{
10
    protected $response;
11
    protected $transformer;
12
13
    /**
14
     * Api response.
15
     *
16
     * @param Psr7Response     $response
17
     * @param Transformer|null $transformer
18
     */
19 15
    public function __construct(Psr7Response $response, Transformer $transformer = null)
20
    {
21 15
        $this->response = $response;
22 15
        $this->transformer = $transformer;
23 15
    }
24
25
    /**
26
     * get the guzzle promisse.
27
     *
28
     * @return GuzzleHttp\Psr7\Response
29
     */
30 3
    public function promise()
31
    {
32 3
        return $this->response;
33
    }
34
35
    /**
36
     * Return a transformed response.
37
     *
38
     * @return array
39
     */
40 12
    public function getBody()
41
    {
42 12
        $body = json_decode($this->response->getBody(), true);
43
44 12
        if (!$body) {
45 3
            throw new ResponseWithoutBody('Response without body');
46
        }
47
48 9
        if (!$this->transformer) {
49 6
            return $body;
50
        }
51
52 3
        return $this->transformer->transformData($body);
53
    }
54
}
55