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 |
||
21 | class MartinHotelNewsHandler extends XoopsObjectHandler |
||
22 | { |
||
23 | /** |
||
24 | * @get rows |
||
25 | * @license http://www.blags.org/ |
||
26 | * @created :2010年06月20日 13时09分 |
||
27 | * @copyright 1997-2010 The Martin Group |
||
28 | * @author Martin <[email protected]> |
||
29 | * @param $sql |
||
30 | * @param null $key |
||
31 | * @return array |
||
32 | */ |
||
33 | View Code Duplication | public function GetRows($sql, $key = null) |
|
48 | |||
49 | /** |
||
50 | * @get hotel news |
||
51 | * @method: |
||
52 | * @license http://www.blags.org/ |
||
53 | * @created :2010年06月29日 20时38分 |
||
54 | * @copyright 1997-2010 The Martin Group |
||
55 | * @author Martin <[email protected]> |
||
56 | * @param $artids |
||
57 | * @return array|string |
||
58 | */ |
||
59 | public function GetHotelNews($artids) |
||
82 | } |
||
83 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.