| Conditions | 71 |
| Paths | 13447 |
| Total Lines | 124 |
| Code Lines | 101 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 354 | function recess_prettify($day, $month, $year, $body) { |
||
| 355 | global $recessdates; |
||
| 356 | $dates = $recessdates[$body]; |
||
| 357 | $recess = 0; |
||
| 358 | $from = ''; |
||
| 359 | $to = ''; |
||
| 360 | if (isset($dates[$year][$month]['all'])) { |
||
| 361 | $recess = 'Summer Recess'; |
||
| 362 | if (isset($dates[$year][7]['all'])) { |
||
| 363 | $from = "$year-6-" . $dates[$year][6]['more']; |
||
| 364 | } else { |
||
| 365 | $from = "$year-7-" . $dates[$year][7]['more']; |
||
| 366 | } |
||
| 367 | if (!isset($dates[$year][9])) { |
||
| 368 | $to = "$year-08-31"; |
||
| 369 | } elseif (isset($dates[$year][9]['all'])) { |
||
| 370 | $to = "$year-10-" . $dates[$year][10]['less']; |
||
| 371 | } else { |
||
| 372 | $to = "$year-9-" . $dates[$year][9]['less']; |
||
| 373 | } |
||
| 374 | } |
||
| 375 | if ((isset($dates[$year][$month]['less']) && $day < $dates[$year][$month]['less']) |
||
| 376 | || (isset($dates[$year][$month]['more']) && $day > $dates[$year][$month]['more']) |
||
| 377 | || (isset($dates[$year][$month]['between']) && $day > $dates[$year][$month]['between'][0] && $day < $dates[$year][$month]['between'][1]) |
||
| 378 | || (isset($dates[$year][$month]['between'][2]) && $day > $dates[$year][$month]['between'][2] && $day < $dates[$year][$month]['between'][3])) { |
||
| 379 | switch ($month) { |
||
| 380 | case 1: case 12: $recess = 'Christmas Recess'; |
||
| 381 | break; |
||
| 382 | case 2: if ($body == 1 || $body == 101) { |
||
| 383 | $recess = 'Half Term Week'; |
||
| 384 | } elseif ($body == 4) { |
||
| 385 | $recess = 'February Recess'; |
||
| 386 | } |
||
| 387 | break; |
||
| 388 | case 3: if ($body == 1 || $body == 101) { |
||
| 389 | $recess = 'Easter Recess'; |
||
| 390 | } elseif ($body == 4) { |
||
| 391 | $recess = 'Spring Recess'; |
||
| 392 | } |
||
| 393 | break; |
||
| 394 | case 4: if (isset($dates[$year][$month]['more']) && $day > $dates[$year][$month]['more']) { |
||
| 395 | $recess = 'Election Recess'; |
||
| 396 | } elseif ($body == 4 && $year == 2003) { |
||
| 397 | $recess = 'Election Recess'; |
||
| 398 | } elseif ($body == 1 || $body == 101) { |
||
| 399 | $recess = 'Easter Recess'; |
||
| 400 | } elseif ($body == 4) { |
||
| 401 | $recess = 'Spring Recess'; |
||
| 402 | } |
||
| 403 | break; |
||
| 404 | case 5: if ($year == 2001 || (isset($dates[$year][$month]['less']) && $day < $dates[$year][$month]['less'])) { |
||
| 405 | $recess = 'Election Recess'; |
||
| 406 | } else { |
||
| 407 | $recess = 'Whit Recess'; |
||
| 408 | } |
||
| 409 | break; |
||
| 410 | case 6: if ($year == 2001) { |
||
| 411 | $recess = 'Election Recess'; |
||
| 412 | } elseif ($body == 1 || $body == 101) { |
||
| 413 | $recess = 'Whit Recess'; |
||
| 414 | } elseif ($body == 4) { |
||
| 415 | $recess = 'Summer Recess'; |
||
| 416 | } else { |
||
| 417 | trigger_error("Argh6"); |
||
| 418 | } |
||
| 419 | break; |
||
| 420 | case 7: case 8: $recess = 'Summer Recess'; |
||
| 421 | break; |
||
| 422 | case 9: if (isset($dates[$year][$month]['less']) && $day < $dates[$year][$month]['less']) { |
||
| 423 | $recess = 'Summer Recess'; |
||
| 424 | } elseif ($body == 1 || $body == 101) { |
||
| 425 | $recess = 'Conference Recess'; |
||
| 426 | } else { |
||
| 427 | trigger_error("Argh9"); |
||
| 428 | } |
||
| 429 | break; |
||
| 430 | case 10: if ($body == 1 || $body == 101) { |
||
| 431 | $recess = 'Conference Recess'; |
||
| 432 | } elseif ($body == 4) { |
||
| 433 | $recess = 'Autumn Recess'; |
||
| 434 | } elseif ($body == 5) { |
||
| 435 | $recess = 'Halloween Recess'; |
||
| 436 | } |
||
| 437 | break; |
||
| 438 | case 11: $recess = 'Autumn Recess'; |
||
| 439 | break; |
||
| 440 | default: $recess = 1; |
||
| 441 | } |
||
| 442 | if (isset($dates[$year][$month]['less']) && $day < $dates[$year][$month]['less']) { |
||
| 443 | $to = "$year-$month-" . $dates[$year][$month]['less']; |
||
| 444 | if ($month == 1) { |
||
| 445 | $from = ($year - 1) . "-12-" . $dates[$year - 1][12]['more']; |
||
| 446 | } else { |
||
| 447 | for ($newmonth = $month - 1; $newmonth >= 1; $newmonth--) { |
||
| 448 | if (isset($dates[$year][$newmonth]['more'])) { |
||
| 449 | $from = "$year-" . ($newmonth) . "-" . $dates[$year][$newmonth]['more']; |
||
| 450 | break; |
||
| 451 | } |
||
| 452 | } |
||
| 453 | } |
||
| 454 | } |
||
| 455 | if (isset($dates[$year][$month]['more']) && $day > $dates[$year][$month]['more']) { |
||
| 456 | $from = "$year-$month-" . $dates[$year][$month]['more']; |
||
| 457 | if ($month == 12) { |
||
| 458 | $to = ($year + 1) . "-01-" . $dates[$year + 1][1]['less']; |
||
| 459 | } else { |
||
| 460 | for ($newmonth = $month + 1; $newmonth <= 12; $newmonth++) { |
||
| 461 | if (isset($dates[$year][$newmonth]['less'])) { |
||
| 462 | $to = "$year-" . ($newmonth) . "-" . $dates[$year][$newmonth]['less']; |
||
| 463 | break; |
||
| 464 | } |
||
| 465 | } |
||
| 466 | } |
||
| 467 | } |
||
| 468 | if (isset($dates[$year][$month]['between']) && $day > $dates[$year][$month]['between'][0] && $day < $dates[$year][$month]['between'][1]) { |
||
| 469 | $from = "$year-$month-" . $dates[$year][$month]['between'][0]; |
||
| 470 | $to = "$year-$month-" . $dates[$year][$month]['between'][1]; |
||
| 471 | } |
||
| 472 | if (isset($dates[$year][$month]['between'][2]) && $day > $dates[$year][$month]['between'][2] && $day < $dates[$year][$month]['between'][3]) { |
||
| 473 | $from = "$year-$month-" . $dates[$year][$month]['between'][2]; |
||
| 474 | $to = "$year-$month-" . $dates[$year][$month]['between'][3]; |
||
| 475 | } |
||
| 476 | } |
||
| 477 | return [$recess, $from, $to]; |
||
| 478 | } |
||
| 479 |