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

Response::getBody()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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