| Conditions | 17 |
| Paths | 119 |
| Total Lines | 85 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
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 | |||
| 233 | $this->next->call(); |
||
| 234 | |||
| 235 | if($this->app->response->getStatus() == 200 && $this->app->fmt !== 'json') |
||
| 236 | { |
||
| 237 | $data = json_decode($this->app->response->getBody()); |
||
| 238 | $text = false; |
||
|
|
|||
| 239 | switch($this->app->fmt) |
||
| 240 | { |
||
| 241 | case 'data-table': |
||
| 242 | $this->app->response->headers->set('Content-Type', 'application/json'); |
||
| 243 | $text = json_encode(array('data'=>$data)); |
||
| 244 | break; |
||
| 245 | case 'csv': |
||
| 246 | $this->app->response->headers->set('Content-Type', 'text/csv'); |
||
| 247 | $path = $this->app->request->getPathInfo(); |
||
| 248 | $path = strrchr($path, '/'); |
||
| 249 | $path = substr($path, 1); |
||
| 250 | $this->app->response->headers->set('Content-Disposition', 'attachment; filename='.$path.'.csv'); |
||
| 251 | $text = $this->createCSV($data); |
||
| 252 | break; |
||
| 253 | case 'xml': |
||
| 254 | $this->app->response->headers->set('Content-Type', 'application/xml'); |
||
| 255 | $text = $this->createXML($data); |
||
| 256 | break; |
||
| 257 | case 'passthru': |
||
| 258 | $text = $this->app->response->getBody(); |
||
| 259 | break; |
||
| 260 | default: |
||
| 261 | $text = 'Unknown fmt '.$fmt; |
||
| 262 | break; |
||
| 263 | } |
||
| 264 | $this->app->response->setBody($text); |
||
| 265 | } |
||
| 266 | else if($this->app->response->getStatus() == 200) |
||
| 267 | { |
||
| 268 | $this->app->response->headers->set('Content-Type', 'application/json;odata.metadata=none'); |
||
| 269 | } |
||
| 270 | } |
||
| 271 | } |
||
| 315 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.