Response   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 75
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A getHttpCode() 0 4 1
A getResponse() 0 4 1
A getResponseHeaders() 0 4 1
1
<?php
2
3
namespace DominionEnterprises\Api;
4
use DominionEnterprises\Util;
5
6
/**
7
 * Represents a response to an API request
8
 */
9
final class Response
10
{
11
    /**
12
     * The http status of the response.
13
     *
14
     * @var int
15
     */
16
    private $_httpCode;
17
18
    /**
19
     * The response from the API
20
     *
21
     * @var array
22
     */
23
    private $_body;
24
25
    /**
26
     * A array of headers received with the response.
27
     *
28
     * @var array array where each header key has an array of values
29
     */
30
    private $_headers;
31
32
    /**
33
     * Create a new instance of Response
34
     *
35
     * @param int $httpCode
36
     * @param array $headers
37
     * @param array $body
38
     *
39
     * @throws \InvalidArgumentException Throw if $httpCode is not an integer between 100 and 600
40
     */
41
    public function __construct($httpCode, array $headers, array $body = [])
42
    {
43
        Util::throwIfNotType(['int' => $httpCode, 'array' => $headers]);
44
45
        if ($httpCode < 100 || $httpCode > 600) {
46
            throw new \InvalidArgumentException('$httpCode must be an integer >= 100 and <= 600');
47
        }
48
49
        $this->_httpCode = $httpCode;
50
        $this->_headers = $headers;
51
        $this->_body = $body;
52
    }
53
54
    /**
55
     * Returns the HTTP status code of the response
56
     *
57
     * @return int
58
     */
59
    public function getHttpCode()
60
    {
61
        return $this->_httpCode;
62
    }
63
64
    /**
65
     * Returns an array representing the response from the API
66
     *
67
     * @return array
68
     */
69
    public function getResponse()
70
    {
71
        return $this->_body;
72
    }
73
74
    /**
75
     * Returns the parsed response headers from the API
76
     *
77
     * @return array array where each header key has an array of values
78
     */
79
    public function getResponseHeaders()
80
    {
81
        return $this->_headers;
82
    }
83
}
84