Conditions | 18 |
Paths | 231 |
Total Lines | 91 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
186 | public function call() |
||
187 | { |
||
188 | if($this->app->request->isOptions()) |
||
189 | { |
||
190 | return; |
||
191 | } |
||
192 | $params = $this->app->request->params(); |
||
193 | $fmt = null; |
||
194 | if(isset($params['fmt'])) |
||
195 | { |
||
196 | $fmt = $params['fmt']; |
||
197 | } |
||
198 | if($fmt === null && isset($params['$format'])) |
||
199 | { |
||
200 | $fmt = $params['$format']; |
||
201 | if(strstr($fmt, 'odata.streaming=true')) |
||
202 | { |
||
203 | $this->app->response->setStatus(406); |
||
204 | return; |
||
205 | } |
||
206 | } |
||
207 | if($fmt === null) |
||
208 | { |
||
209 | $mimeType = $this->app->request->headers->get('Accept'); |
||
210 | if(strstr($mimeType, 'odata.streaming=true')) |
||
211 | { |
||
212 | $this->app->response->setStatus(406); |
||
213 | return; |
||
214 | } |
||
215 | switch($mimeType) |
||
216 | { |
||
217 | case 'text/csv': |
||
218 | $fmt = 'csv'; |
||
219 | break; |
||
220 | case 'text/x-vCard': |
||
221 | $fmt = 'vcard'; |
||
222 | break; |
||
223 | default: |
||
224 | $fmt = 'json'; |
||
225 | break; |
||
226 | } |
||
227 | } |
||
228 | |||
229 | $this->app->fmt = $fmt; |
||
230 | $this->app->odata = new ODataParams($params); |
||
231 | |||
232 | $this->app->isLocal = false; |
||
233 | if($_SERVER['SERVER_ADDR'] === $_SERVER['REMOTE_ADDR']) |
||
234 | { |
||
235 | $this->app->isLocal = true; |
||
236 | } |
||
237 | |||
238 | |||
239 | $this->next->call(); |
||
240 | |||
241 | if($this->app->response->getStatus() == 200 && $this->app->fmt !== 'json') |
||
242 | { |
||
243 | $data = json_decode($this->app->response->getBody()); |
||
244 | $text = false; |
||
|
|||
245 | switch($this->app->fmt) |
||
246 | { |
||
247 | case 'data-table': |
||
248 | $this->app->response->headers->set('Content-Type', 'application/json'); |
||
249 | $text = json_encode(array('data'=>$data)); |
||
250 | break; |
||
251 | case 'csv': |
||
252 | $this->app->response->headers->set('Content-Type', 'text/csv'); |
||
253 | $path = $this->app->request->getPathInfo(); |
||
254 | $path = strrchr($path, '/'); |
||
255 | $path = substr($path, 1); |
||
256 | $this->app->response->headers->set('Content-Disposition', 'attachment; filename='.$path.'.csv'); |
||
257 | $text = $this->createCSV($data); |
||
258 | break; |
||
259 | case 'xml': |
||
260 | $this->app->response->headers->set('Content-Type', 'application/xml'); |
||
261 | $text = $this->createXML($data); |
||
262 | break; |
||
263 | case 'passthru': |
||
264 | $text = $this->app->response->getBody(); |
||
265 | break; |
||
266 | default: |
||
267 | $text = 'Unknown fmt '.$fmt; |
||
268 | break; |
||
269 | } |
||
270 | $this->app->response->setBody($text); |
||
271 | } |
||
272 | else if($this->app->response->getStatus() == 200) |
||
273 | { |
||
274 | $this->app->response->headers->set('Content-Type', 'application/json;odata.metadata=none'); |
||
275 | } |
||
276 | } |
||
277 | } |
||
321 |
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.