Completed
Push — master ( e43aeb...a61874 )
by Juliano
03:03
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.125

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 4
cp 0.5
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1.125
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