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 $this |
||
43 | */ |
||
44 | 2 | public function setStatusCode($value) |
|
51 | |||
52 | |||
53 | |||
54 | /** |
||
55 | * Set headers. |
||
56 | * |
||
57 | * @param string $header type of header to set |
||
58 | * |
||
59 | * @return $this |
||
60 | */ |
||
61 | public function addHeader($header) |
||
65 | |||
66 | |||
67 | |||
68 | /** |
||
69 | * Check if headers are already sent and throw exception if it is. |
||
70 | * |
||
71 | * @return void |
||
72 | * |
||
73 | * @throws Exception |
||
74 | */ |
||
75 | 1 | public function checkIfHeadersAlreadySent() |
|
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * Send headers. |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | public function sendHeaders() |
||
103 | |||
104 | |||
105 | |||
106 | /** |
||
107 | * Set the body. |
||
108 | * |
||
109 | * @param callable|string $body either a string or a callable that |
||
110 | * can generate the body. |
||
111 | * |
||
112 | * @return this |
||
113 | */ |
||
114 | 1 | public function setBody($body) |
|
127 | |||
128 | |||
129 | |||
130 | /** |
||
131 | * Get the body. |
||
132 | * |
||
133 | * @return void |
||
134 | */ |
||
135 | 1 | public function getBody() |
|
139 | |||
140 | |||
141 | |||
142 | /** |
||
143 | * Send response with an optional statuscode. |
||
144 | * |
||
145 | * @param integer $statusCode optional statuscode to send. |
||
146 | * |
||
147 | * @return void |
||
148 | */ |
||
149 | public function send($statusCode = null) |
||
160 | |||
161 | |||
162 | |||
163 | /** |
||
164 | * Send JSON response with an optional statuscode. |
||
165 | * |
||
166 | * @param mixed $data to be encoded as json. |
||
167 | * @param integer $statusCode optional statuscode to send. |
||
168 | * |
||
169 | * @return void |
||
170 | */ |
||
171 | public function sendJson($data, $statusCode = null) |
||
183 | |||
184 | |||
185 | |||
186 | /** |
||
187 | * Redirect to another page. |
||
188 | * |
||
189 | * @param string $url to redirect to |
||
190 | * |
||
191 | * @return void |
||
192 | * |
||
193 | * @SuppressWarnings(PHPMD.ExitExpression) |
||
194 | */ |
||
195 | public function redirect($url) |
||
201 | } |
||
202 |
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.