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

JCResponse   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 49
c 0
b 0
f 0
wmc 6
lcom 2
cbo 1
ccs 12
cts 14
cp 0.8571
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A status() 0 4 1
A body() 0 4 1
A headers() 0 4 1
A json() 0 4 1
A success() 0 4 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
}