Completed
Push — master ( 0deb12...7308a5 )
by Jared
03:53 queued 01:30
created

JCResponse::json()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jaredchu
5
 * Date: 31/05/2017
6
 * Time: 09:50
7
 */
8
9
namespace JC;
10
11
12
use Psr\Http\Message\ResponseInterface;
13
use GuzzleHttp;
14
15
class JCResponse implements iJCResponse
16
{
17
18
    /**
19
     * @var ResponseInterface
20
     */
21
    public $response;
22
23
    /**
24
     * @var string
25
     */
26
    protected $body;
27
28
    /**
29
     * JCResponse constructor.
30
     * @param $response
31
     */
32
    public function __construct($response)
33
    {
34
        $this->response = $response;
35
        $this->body = $this->response->getBody()->getContents();
36
    }
37
38
39
    public function status()
40
    {
41
        return $this->response->getStatusCode();
42
    }
43
44
    public function body()
45
    {
46
        return $this->body;
47
    }
48
49
    public function headers()
50
    {
51
        return $this->response->getHeaders();
52
    }
53
54
    public function json()
55
    {
56
        return GuzzleHttp\json_decode($this->body());
57
    }
58
59
    public function success()
60
    {
61
        return $this->response->getStatusCode() < 300;
62
    }
63
}