Completed
Pull Request — develop (#20)
by Johan
04:02 queued 02:15
created

Response::getHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Artstorm\MonkeyLearn\HttpClient;
4
5
class Response
6
{
7
    /**
8
     * HTTP Status code
9
     *
10
     * @int
11
     */
12
    protected $status;
13
14
    /**
15
     * Headers.
16
     *
17
     * @var array
18
     */
19
    protected $headers;
20
21
    /**
22
     * Contents.
23
     *
24
     * @var string
25
     */
26
    protected $body;
27
28
    /**
29
     * Assign dependencies.
30
     *
31
     * @param int    $status
32
     * @param array  $headers
33
     * @param string $body
34
     */
35 22
    public function __construct($status = 200, array $headers = [], $body = null)
36
    {
37 22
        $this->status = $status;
38 22
        $this->headers = $headers;
39 22
        $this->body = $body;
40 22
    }
41
42
    /**
43
     * Get body.
44
     *
45
     * @return string
46
     */
47 10
    public function getBody()
48
    {
49 10
        return $this->body;
50
    }
51
52
    /**
53
     * Get HTTP status code.
54
     *
55
     * @return string
56
     */
57 4
    public function getStatus()
58
    {
59 4
        return $this->status;
60
    }
61
62
    /**
63
     * Get response headers.
64
     *
65
     * @return array
66
     */
67 2
    public function getHeaders()
68
    {
69 2
        return $this->headers;
70
    }
71
72
    /**
73
     * Get a response header by key.
74
     *
75
     * @param  string $key
76
     *
77
     * @return string
78
     */
79 4
    public function getHeader($key)
80
    {
81 4
        if (array_key_exists($key, $this->headers)) {
82 2
            return $this->headers[$key];
83
        }
84 2
    }
85
}
86