1 | <?php |
||
16 | class Response extends PhResponse |
||
17 | { |
||
18 | const OK = 200; |
||
19 | const CREATED = 201; |
||
20 | const ACCEPTED = 202; |
||
21 | const MOVED_PERMANENTLY = 301; |
||
22 | const FOUND = 302; |
||
23 | const TEMPORARY_REDIRECT = 307; |
||
24 | const PERMANENTLY_REDIRECT = 308; |
||
25 | const BAD_REQUEST = 400; |
||
26 | const UNAUTHORIZED = 401; |
||
27 | const FORBIDDEN = 403; |
||
28 | const NOT_FOUND = 404; |
||
29 | const NOT_ACCEPTABLE = 406; |
||
30 | const INTERNAL_SERVER_ERROR = 500; |
||
31 | const NOT_IMPLEMENTED = 501; |
||
32 | const BAD_GATEWAY = 502; |
||
33 | const UNPROCESSABLE_ENTITY = 422; |
||
34 | |||
35 | private $codes = [ |
||
36 | 200 => 'OK', |
||
37 | 301 => 'Moved Permanently', |
||
38 | 302 => 'Found', |
||
39 | 307 => 'Temporary Redirect', |
||
40 | 308 => 'Permanent Redirect', |
||
41 | 400 => 'Bad Request', |
||
42 | 401 => 'Unauthorized', |
||
43 | 403 => 'Forbidden', |
||
44 | 404 => 'Not Found', |
||
45 | 422 => 'Unprocessable Entity', |
||
46 | 500 => 'Internal Server Error', |
||
47 | 501 => 'Not Implemented', |
||
48 | 502 => 'Bad Gateway', |
||
49 | ]; |
||
50 | 1 | ||
51 | /** |
||
52 | 1 | * Returns the http code description or if not found the code itself. |
|
53 | 1 | * @param int $code |
|
54 | * |
||
55 | * @return int|string |
||
56 | 1 | */ |
|
57 | public function getHttpCodeDescription(int $code) |
||
65 | |||
66 | /** |
||
67 | * Send the response back. |
||
68 | * |
||
69 | * @return PhResponse |
||
70 | */ |
||
71 | public function send(): PhResponse |
||
111 | |||
112 | /** |
||
113 | 1 | * Sets the payload code as Error. |
|
114 | * |
||
115 | * @param string $detail |
||
116 | * |
||
117 | * @return Response |
||
118 | */ |
||
119 | public function setPayloadError(string $detail = ''): Response |
||
130 | |||
131 | /** |
||
132 | * Traverses the errors collection and sets the errors in the payload. |
||
133 | * |
||
134 | * @param ModelMessage[]|ValidationMessage $errors |
||
135 | * |
||
136 | * @return Response |
||
137 | */ |
||
138 | public function setPayloadErrors($errors): Response |
||
149 | 1 | ||
150 | /** |
||
151 | * Sets the payload code as Success. |
||
152 | * |
||
153 | * @param null|string|array $content The content |
||
154 | * |
||
155 | * @return Response |
||
156 | */ |
||
157 | public function setPayloadSuccess($content = []): Response |
||
166 | |||
167 | /** |
||
168 | * Handle the exception we throw from our api. |
||
169 | * |
||
170 | * @param Throwable $e |
||
171 | * @return Response |
||
172 | */ |
||
173 | public function handleException(Throwable $e): Response |
||
203 | } |
||
204 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.