Completed
Push — master ( e43aeb...a61874 )
by Juliano
03:03
created

Response   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 64.71%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 1
cbo 2
dl 0
loc 43
ccs 11
cts 17
cp 0.6471
rs 10

3 Methods

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