1 | <?php |
||
8 | class Response |
||
9 | { |
||
10 | /** |
||
11 | * @var array $headers set all headers to send. |
||
12 | * @var array $statusCode set statuscode to use. |
||
13 | * @var array $body body to send with response. |
||
14 | */ |
||
15 | private $headers = []; |
||
16 | private $statusCode; |
||
17 | private $body; |
||
18 | |||
19 | |||
20 | |||
21 | /** |
||
22 | * @var array $validStatusCode these status codes are supported. |
||
23 | */ |
||
24 | private $validStatusCode = [ |
||
25 | "200" => "HTTP/1.1 200 OK", |
||
26 | "400" => "HTTP/1.1 400 Bad Request", |
||
27 | "403" => "HTTP/1.1 403 Forbidden", |
||
28 | "404" => "HTTP/1.1 404 Not Found", |
||
29 | "405" => "HTTP/1.1 405 Method Not Allowed", |
||
30 | "418" => "HTTP/1.1 418 I'm a teapot", |
||
31 | "500" => "HTTP/1.1 500 Internal Server Error", |
||
32 | "501" => "HTTP/1.1 501 Not Implemented", |
||
33 | ]; |
||
34 | |||
35 | |||
36 | |||
37 | /** |
||
38 | * Set status code to be sent as part of headers. |
||
39 | * |
||
40 | * @param string $header type of header to set |
||
|
|||
41 | * |
||
42 | * @return self |
||
43 | */ |
||
44 | 2 | public function setStatusCode($value) |
|
57 | |||
58 | |||
59 | |||
60 | /** |
||
61 | * Get status code to be sent as part of headers. |
||
62 | * |
||
63 | * @return integer value as status code or null if not set. |
||
64 | */ |
||
65 | public function getStatusCode() |
||
69 | |||
70 | |||
71 | |||
72 | /** |
||
73 | * Set headers. |
||
74 | * |
||
75 | * @param string $header type of header to set |
||
76 | * |
||
77 | * @return self |
||
78 | */ |
||
79 | public function addHeader($header) |
||
84 | |||
85 | |||
86 | |||
87 | /** |
||
88 | * Check if headers are already sent and throw exception if it has, |
||
89 | * but ignore when running in cli mode. |
||
90 | * |
||
91 | * @return void |
||
92 | * |
||
93 | * @throws Exception |
||
94 | */ |
||
95 | public function checkIfHeadersAlreadySent() |
||
101 | |||
102 | |||
103 | |||
104 | /** |
||
105 | * Send headers. |
||
106 | * |
||
107 | * @return self |
||
108 | */ |
||
109 | public function sendHeaders() |
||
123 | |||
124 | |||
125 | |||
126 | /** |
||
127 | * Set the body. |
||
128 | * |
||
129 | * @param callable|string $body either a string or a callable that |
||
130 | * can generate the body. |
||
131 | * |
||
132 | * @return self |
||
133 | */ |
||
134 | 1 | public function setBody($body) |
|
147 | |||
148 | |||
149 | |||
150 | /** |
||
151 | * Get the body. |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | 1 | public function getBody() |
|
159 | |||
160 | |||
161 | |||
162 | /** |
||
163 | * Send response with an optional statuscode. |
||
164 | * |
||
165 | * @param integer $statusCode optional statuscode to send. |
||
166 | * |
||
167 | * @return self |
||
168 | */ |
||
169 | public function send($statusCode = null) |
||
180 | |||
181 | |||
182 | |||
183 | /** |
||
184 | * Send JSON response with an optional statuscode. |
||
185 | * |
||
186 | * @param mixed $data to be encoded as json. |
||
187 | * @param integer $statusCode optional statuscode to send. |
||
188 | * |
||
189 | * @return self |
||
190 | */ |
||
191 | public function sendJson($data, $statusCode = null) |
||
197 | |||
198 | |||
199 | |||
200 | /** |
||
201 | * Set body with JSON data. |
||
202 | * |
||
203 | * @param mixed $data to be encoded as json. |
||
204 | * |
||
205 | * @return self |
||
206 | */ |
||
207 | public function setJsonBody($data) |
||
213 | |||
214 | |||
215 | |||
216 | /** |
||
217 | * Redirect to another page. |
||
218 | * |
||
219 | * @param string $url to redirect to |
||
220 | * |
||
221 | * @return void |
||
222 | * |
||
223 | * @SuppressWarnings(PHPMD.ExitExpression) |
||
224 | */ |
||
225 | public function redirect($url) |
||
231 | } |
||
232 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.