| Conditions | 9 |
| Paths | 9 |
| Total Lines | 142 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 90 |
| Changes | 1 | ||
| Bugs | 0 | 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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php |
||
| 207 | public function IndentedRectangle($xt, $yt, $w, $h, $iw = 0, $ih = 0, $aCorner = 3, $aFillColor = '', $r = 4) |
||
| 208 | { |
||
| 209 | list($xt, $yt) = $this->scale->Translate($xt, $yt); |
||
| 210 | list($w, $h) = $this->scale->Translate($w, $h); |
||
| 211 | list($iw, $ih) = $this->scale->Translate($iw, $ih); |
||
| 212 | |||
| 213 | $xr = $xt + $w - 0; |
||
| 214 | $yl = $yt + $h - 0; |
||
| 215 | |||
| 216 | switch ($aCorner) { |
||
| 217 | case 0: |
||
| 218 | // Bottom line, left & right arc |
||
| 219 | $this->img->Line($xt + $r, $yl, $xr - $r, $yl); |
||
| 220 | $this->img->Arc($xt + $r, $yl - $r, $r * 2, $r * 2, 90, 180); |
||
| 221 | $this->img->Arc($xr - $r, $yl - $r, $r * 2, $r * 2, 0, 90); |
||
| 222 | |||
| 223 | // Right line, Top right arc |
||
| 224 | $this->img->Line($xr, $yt + $r, $xr, $yl - $r); |
||
| 225 | $this->img->Arc($xr - $r, $yt + $r, $r * 2, $r * 2, 270, 360); |
||
| 226 | |||
| 227 | // Top line, Top left arc |
||
| 228 | $this->img->Line($xt + $iw + $r, $yt, $xr - $r, $yt); |
||
| 229 | $this->img->Arc($xt + $iw + $r, $yt + $r, $r * 2, $r * 2, 180, 270); |
||
| 230 | |||
| 231 | // Left line |
||
| 232 | $this->img->Line($xt, $yt + $ih + $r, $xt, $yl - $r); |
||
| 233 | |||
| 234 | // Indent horizontal, Lower left arc |
||
| 235 | $this->img->Line($xt + $r, $yt + $ih, $xt + $iw - $r, $yt + $ih); |
||
| 236 | $this->img->Arc($xt + $r, $yt + $ih + $r, $r * 2, $r * 2, 180, 270); |
||
| 237 | |||
| 238 | // Indent vertical, Indent arc |
||
| 239 | $this->img->Line($xt + $iw, $yt + $r, $xt + $iw, $yt + $ih - $r); |
||
| 240 | $this->img->Arc($xt + $iw - $r, $yt + $ih - $r, $r * 2, $r * 2, 0, 90); |
||
| 241 | |||
| 242 | if ($aFillColor != '') { |
||
| 243 | $bc = $this->img->current_color_name; |
||
| 244 | $this->img->PushColor($aFillColor); |
||
| 245 | $this->img->FillToBorder($xr - $r, $yl - $r, $bc); |
||
| 246 | $this->img->PopColor(); |
||
| 247 | } |
||
| 248 | |||
| 249 | break; |
||
| 250 | case 1: |
||
| 251 | // Bottom line, left & right arc |
||
| 252 | $this->img->Line($xt + $r, $yl, $xr - $r, $yl); |
||
| 253 | $this->img->Arc($xt + $r, $yl - $r, $r * 2, $r * 2, 90, 180); |
||
| 254 | $this->img->Arc($xr - $r, $yl - $r, $r * 2, $r * 2, 0, 90); |
||
| 255 | |||
| 256 | // Left line, Top left arc |
||
| 257 | $this->img->Line($xt, $yt + $r, $xt, $yl - $r); |
||
| 258 | $this->img->Arc($xt + $r, $yt + $r, $r * 2, $r * 2, 180, 270); |
||
| 259 | |||
| 260 | // Top line, Top right arc |
||
| 261 | $this->img->Line($xt + $r, $yt, $xr - $iw - $r, $yt); |
||
| 262 | $this->img->Arc($xr - $iw - $r, $yt + $r, $r * 2, $r * 2, 270, 360); |
||
| 263 | |||
| 264 | // Right line |
||
| 265 | $this->img->Line($xr, $yt + $ih + $r, $xr, $yl - $r); |
||
| 266 | |||
| 267 | // Indent horizontal, Lower right arc |
||
| 268 | $this->img->Line($xr - $iw + $r, $yt + $ih, $xr - $r, $yt + $ih); |
||
| 269 | $this->img->Arc($xr - $r, $yt + $ih + $r, $r * 2, $r * 2, 270, 360); |
||
| 270 | |||
| 271 | // Indent vertical, Indent arc |
||
| 272 | $this->img->Line($xr - $iw, $yt + $r, $xr - $iw, $yt + $ih - $r); |
||
| 273 | $this->img->Arc($xr - $iw + $r, $yt + $ih - $r, $r * 2, $r * 2, 90, 180); |
||
| 274 | |||
| 275 | if ($aFillColor != '') { |
||
| 276 | $bc = $this->img->current_color_name; |
||
| 277 | $this->img->PushColor($aFillColor); |
||
| 278 | $this->img->FillToBorder($xt + $r, $yl - $r, $bc); |
||
| 279 | $this->img->PopColor(); |
||
| 280 | } |
||
| 281 | |||
| 282 | break; |
||
| 283 | case 2: // Lower right |
||
| 284 | // Top line, Top left & Top right arc |
||
| 285 | $this->img->Line($xt + $r, $yt, $xr - $r, $yt); |
||
| 286 | $this->img->Arc($xt + $r, $yt + $r, $r * 2, $r * 2, 180, 270); |
||
| 287 | $this->img->Arc($xr - $r, $yt + $r, $r * 2, $r * 2, 270, 360); |
||
| 288 | |||
| 289 | // Left line, Bottom left arc |
||
| 290 | $this->img->Line($xt, $yt + $r, $xt, $yl - $r); |
||
| 291 | $this->img->Arc($xt + $r, $yl - $r, $r * 2, $r * 2, 90, 180); |
||
| 292 | |||
| 293 | // Bottom line, Bottom right arc |
||
| 294 | $this->img->Line($xt + $r, $yl, $xr - $iw - $r, $yl); |
||
| 295 | $this->img->Arc($xr - $iw - $r, $yl - $r, $r * 2, $r * 2, 0, 90); |
||
| 296 | |||
| 297 | // Right line |
||
| 298 | $this->img->Line($xr, $yt + $r, $xr, $yl - $ih - $r); |
||
| 299 | |||
| 300 | // Indent horizontal, Lower right arc |
||
| 301 | $this->img->Line($xr - $r, $yl - $ih, $xr - $iw + $r, $yl - $ih); |
||
| 302 | $this->img->Arc($xr - $r, $yl - $ih - $r, $r * 2, $r * 2, 0, 90); |
||
| 303 | |||
| 304 | // Indent vertical, Indent arc |
||
| 305 | $this->img->Line($xr - $iw, $yl - $r, $xr - $iw, $yl - $ih + $r); |
||
| 306 | $this->img->Arc($xr - $iw + $r, $yl - $ih + $r, $r * 2, $r * 2, 180, 270); |
||
| 307 | |||
| 308 | if ($aFillColor != '') { |
||
| 309 | $bc = $this->img->current_color_name; |
||
| 310 | $this->img->PushColor($aFillColor); |
||
| 311 | $this->img->FillToBorder($xt + $r, $yt + $r, $bc); |
||
| 312 | $this->img->PopColor(); |
||
| 313 | } |
||
| 314 | |||
| 315 | break; |
||
| 316 | case 3: // Lower left |
||
| 317 | // Top line, Top left & Top right arc |
||
| 318 | $this->img->Line($xt + $r, $yt, $xr - $r, $yt); |
||
| 319 | $this->img->Arc($xt + $r, $yt + $r, $r * 2, $r * 2, 180, 270); |
||
| 320 | $this->img->Arc($xr - $r, $yt + $r, $r * 2, $r * 2, 270, 360); |
||
| 321 | |||
| 322 | // Right line, Bottom right arc |
||
| 323 | $this->img->Line($xr, $yt + $r, $xr, $yl - $r); |
||
| 324 | $this->img->Arc($xr - $r, $yl - $r, $r * 2, $r * 2, 0, 90); |
||
| 325 | |||
| 326 | // Bottom line, Bottom left arc |
||
| 327 | $this->img->Line($xt + $iw + $r, $yl, $xr - $r, $yl); |
||
| 328 | $this->img->Arc($xt + $iw + $r, $yl - $r, $r * 2, $r * 2, 90, 180); |
||
| 329 | |||
| 330 | // Left line |
||
| 331 | $this->img->Line($xt, $yt + $r, $xt, $yl - $ih - $r); |
||
| 332 | |||
| 333 | // Indent horizontal, Lower left arc |
||
| 334 | $this->img->Line($xt + $r, $yl - $ih, $xt + $iw - $r, $yl - $ih); |
||
| 335 | $this->img->Arc($xt + $r, $yl - $ih - $r, $r * 2, $r * 2, 90, 180); |
||
| 336 | |||
| 337 | // Indent vertical, Indent arc |
||
| 338 | $this->img->Line($xt + $iw, $yl - $ih + $r, $xt + $iw, $yl - $r); |
||
| 339 | $this->img->Arc($xt + $iw - $r, $yl - $ih + $r, $r * 2, $r * 2, 270, 360); |
||
| 340 | |||
| 341 | if ($aFillColor != '') { |
||
| 342 | $bc = $this->img->current_color_name; |
||
| 343 | $this->img->PushColor($aFillColor); |
||
| 344 | $this->img->FillToBorder($xr - $r, $yt + $r, $bc); |
||
| 345 | $this->img->PopColor(); |
||
| 346 | } |
||
| 347 | |||
| 348 | break; |
||
| 349 | } |
||
| 352 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.