Completed
Push — master ( a61874...f10773 )
by Juliano
05:06 queued 02:53
created

Response::promise()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 12
    public function __construct(Psr7Response $response, Transformer $transformer = null)
19
    {
20 12
        $this->response = $response;
21 12
        $this->transformer = $transformer;
22 12
    }
23
24
    /**
25
     * get the guzzle promisse.
26
     *
27
     * @return GuzzleHttp\Psr7\Response
28
     */
29 3
    public function promise()
30
    {
31 3
        return $this->response;
32
    }
33
34
    /**
35
     * Return a transformed response.
36
     *
37
     * @return array
38
     */
39 9
    public function getBody()
40
    {
41 9
        $body = json_decode($this->response->getBody(), true);
42
43 9
        if (!$this->transformer) {
44 6
            return $body;
45
        }
46
47 3
        return $this->transformer->transformData($body);
48
    }
49
}
50