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 |
||
| 8 | class MyDateInterval |
||
| 9 | { |
||
|
|
|||
| 10 | |||
| 11 | /** |
||
| 12 | * Returns date pattern for mysql (select part) |
||
| 13 | * @param int|string $dateInterval |
||
| 14 | * @return string |
||
| 15 | */ |
||
| 16 | public static function getDatePattern($dateInterval) { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * |
||
| 32 | * @param string $field |
||
| 33 | * @param array $params (all are optional) |
||
| 34 | * - table |
||
| 35 | * - dateFrom |
||
| 36 | * - dateTo |
||
| 37 | * @return string condition of date range |
||
| 38 | */ |
||
| 39 | View Code Duplication | public static function prepareDateBetweenCondition($field, array $params = []) { |
|
| 48 | |||
| 49 | } |