Passed
Push — master ( 2c35c6...7904fb )
by Jared
02:33
created

JCResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
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 7
    public function __construct($response)
33
    {
34 7
        $this->response = $response;
35 7
        $this->body = $this->response->getBody()->getContents();
36 7
    }
37
38
39 7
    public function status()
40
    {
41 7
        return $this->response->getStatusCode();
42
    }
43
44 7
    public function body()
45
    {
46 7
        return $this->body;
47
    }
48
49 1
    public function headers()
50
    {
51 1
        return $this->response->getHeaders();
52
    }
53
54 6
    public function json()
55
    {
56 6
        return GuzzleHttp\json_decode($this->body());
57
    }
58
59
    public function success()
60
    {
61
        return $this->response->getStatusCode() < 300;
62
    }
63
}