Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 4 | class Lists |
||
| 5 | { |
||
| 6 | /** |
||
| 7 | * @param int|null $start |
||
| 8 | * @param int|null $end |
||
| 9 | * @param int $step |
||
| 10 | * @return YearList |
||
| 11 | */ |
||
| 12 | public static function years($start = null, $end = null, $step = 1) |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param int|null $start |
||
| 19 | * @param int|null $end |
||
| 20 | * @param int $step |
||
| 21 | * @return MonthList |
||
| 22 | */ |
||
| 23 | public static function months($start = 1, $end = 12, $step = 1) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param int|null $start |
||
| 30 | * @param int|null $end |
||
| 31 | * @param int $step |
||
| 32 | * @return GenericList |
||
| 33 | */ |
||
| 34 | View Code Duplication | public static function days($start = 1, $end = 31, $step = 1) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @param int|null $start |
||
| 44 | * @param int|null $end |
||
| 45 | * @param int $step |
||
| 46 | * @return GenericList |
||
| 47 | */ |
||
| 48 | View Code Duplication | public static function hours($start = 0, $end = 23, $step = 1) |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @param int|null $start |
||
| 58 | * @param int|null $end |
||
| 59 | * @param int $step |
||
| 60 | * @return GenericList |
||
| 61 | */ |
||
| 62 | View Code Duplication | public static function minutes($start = 0, $end = 59, $step = 5) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * @param int|null $start |
||
| 72 | * @param int|null $end |
||
| 73 | * @param int $step |
||
| 74 | * @return GenericList |
||
| 75 | */ |
||
| 76 | View Code Duplication | public static function seconds($start = 0, $end = 59, $step = 15) |
|
| 83 | } |