Completed
Pull Request — master (#21)
by Tomas
03:30
created

ConsoleResponse::getResponseHeaders()   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 1
Metric Value
c 1
b 0
f 1
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 Tomaj\NetteApi\Misc;
4
5
class ConsoleResponse
6
{
7
    private $postFields;
8
9
    private $rawPost;
10
11
    private $getFields;
12
13
    private $cookieFields;
14
15
    private $url;
16
17
    private $method;
18
19
    private $headers;
20
21
    private $responseCode;
22
23
    private $responseBody;
24
25
    private $responseHeaders;
26
27
    private $responseTime;
28
29
    private $isError = false;
30
31
    private $errorNumber;
32
33
    private $errorMessage;
34
35
    /**
36
     * ConsoleResponse constructor.
37
     *
38
     * @param string  $url
39
     * @param string  $method
40
     * @param array   $postFields
41
     * @param array   $getFields
42
     * @param array   $cookieFields
43
     * @param array   $headers
44
     * @param string|boolean $rawPost
45
     */
46 9
    public function __construct($url, $method, array $postFields = [], array $getFields = [], $cookieFields = [], array $headers = [], $rawPost = false)
47
    {
48 9
        $this->url = $url;
49 9
        $this->method = $method;
50 9
        $this->postFields = $postFields;
51 9
        $this->getFields = $getFields;
52 9
        $this->cookieFields = $cookieFields;
53 9
        $this->headers = $headers;
54 9
        $this->rawPost = $rawPost;
55 9
    }
56
57
    /**
58
     * Log response from request
59
     *
60
     * @param $responseCode
61
     * @param $responseBody
62
     * @param $responseHeaders
63
     * @param $responseTime
64
     *
65
     * @return voiud
66
     */
67 3
    public function logRequest($responseCode, $responseBody, $responseHeaders, $responseTime)
68
    {
69 3
        $this->responseCode = $responseCode;
70 3
        $this->responseBody = $responseBody;
71 3
        $this->responseHeaders = $responseHeaders;
72 3
        $this->responseTime = $responseTime;
73 3
    }
74
75 6
    public function logError($errorNumber, $errorMessage, $responseTime)
76
    {
77 6
        $this->isError = true;
78 6
        $this->errorNumber = $errorNumber;
79 6
        $this->errorMessage = $errorMessage;
80 6
        $this->responseTime = $responseTime;
81 6
    }
82
83 3
    public function getPostFields()
84
    {
85 3
        return $this->postFields;
86
    }
87
88
    public function getRawPost()
89
    {
90
        return $this->rawPost;
91
    }
92
93 3
    public function getGetFields()
94
    {
95 3
        return $this->getFields;
96
    }
97
98 3
    public function getCookieFields()
99
    {
100 3
        return $this->cookieFields;
101
    }
102
103 6
    public function getUrl()
104
    {
105 6
        return $this->url;
106
    }
107
108 3
    public function getMethod()
109
    {
110 3
        return $this->method;
111
    }
112
113 3
    public function getHeaders()
114
    {
115 3
        return $this->headers;
116
    }
117
118 9
    public function isError()
119
    {
120 9
        return $this->isError;
121
    }
122
123
    /**
124
     * @return integer
125
     */
126 3
    public function getResponseCode()
127
    {
128 3
        return $this->responseCode;
129
    }
130
131
    /**
132
     * @return string
133
     */
134 3
    public function getResponseBody()
135
    {
136 3
        return $this->responseBody;
137
    }
138
139
    /**
140
     * @return string
141
     */
142 3
    public function getFormattedJsonBody()
143
    {
144 3
        $body = $this->responseBody;
145 3
        $decoded = json_decode($body);
146 3
        if ($decoded) {
147
            $body = json_encode($decoded, JSON_PRETTY_PRINT);
148
        }
149 3
        return $body;
150
    }
151
152 3
    public function getResponseHeaders()
153
    {
154 3
        return $this->responseHeaders;
155
    }
156
157
    /**
158
     * @return integer
159
     */
160 6
    public function getResponseTime()
161
    {
162 6
        return $this->responseTime;
163
    }
164
165
    /**
166
     * @return integer
167
     */
168 3
    public function getErrorNumber()
169
    {
170 3
        return $this->errorNumber;
171
    }
172
173
    /**
174
     * @return string
175
     */
176 3
    public function getErrorMessage()
177
    {
178 3
        return $this->errorMessage;
179
    }
180
}
181