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 |
||
50 | class MartinHotelServiceTypeHandler extends XoopsObjectHandler |
||
51 | { |
||
52 | /** |
||
53 | * create a new hotel city |
||
54 | * @param bool $isNew flag the new objects as "new"? |
||
55 | * @return object hotelservicetype |
||
56 | */ |
||
57 | public function &create($isNew = true) |
||
66 | |||
67 | /** |
||
68 | * retrieve a hotel city |
||
69 | * |
||
70 | * @param int $id hotelservicetypeid of the hotelservicetype |
||
71 | * @return mixed reference to the {@link hotelservicetype} object, FALSE if failed |
||
72 | */ |
||
73 | View Code Duplication | public function &get($id) |
|
90 | |||
91 | /** |
||
92 | * @得到列表 |
||
93 | * @method: |
||
94 | * @license http://www.blags.org/ |
||
95 | * @created :2010年05月23日 14时59分 |
||
96 | * @copyright 1997-2010 The Martin Group |
||
97 | * @author Martin <[email protected]> |
||
98 | * @param int $limit |
||
99 | * @param int $start |
||
100 | * @param string $sort |
||
101 | * @param string $order |
||
102 | * @param bool $id_as_key |
||
103 | * @return array |
||
104 | */ |
||
105 | View Code Duplication | public function &getHotelServiceTypes($limit = 0, $start = 0, $sort = 'service_type_id', $order = 'ASC', $id_as_key = true) |
|
117 | |||
118 | /** |
||
119 | * insert a new hotelservicetype in the database |
||
120 | * |
||
121 | * @param object $hotelservicetype reference to the {@link hotelservicetype} object |
||
122 | * @param bool $force |
||
123 | * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
||
124 | */ |
||
125 | public function insert(&$hotelservicetype, $force = false) |
||
171 | |||
172 | /** |
||
173 | * @删除一个城市 |
||
174 | * @method:delete(service_id) |
||
175 | * @license http://www.blags.org/ |
||
176 | * @created :2010年05月21日 20时40分 |
||
177 | * @copyright 1997-2010 The Martin Group |
||
178 | * @author Martin <[email protected]> |
||
179 | * @param object $hotelservicetype |
||
180 | * @param bool $force |
||
181 | * @return bool|void |
||
182 | */ |
||
183 | View Code Duplication | public function delete(&$hotelservicetype, $force = false) |
|
203 | |||
204 | /** |
||
205 | * delete hotel cities matching a set of conditions |
||
206 | * |
||
207 | * @param object $criteria {@link CriteriaElement} |
||
208 | * @return bool FALSE if deletion failed |
||
209 | */ |
||
210 | View Code Duplication | public function deleteAll($criteria = null) |
|
222 | |||
223 | /** |
||
224 | * count hotel cities matching a condition |
||
225 | * |
||
226 | * @param object $criteria {@link CriteriaElement} to match |
||
227 | * @return int count of categories |
||
228 | */ |
||
229 | View Code Duplication | public function getCount($criteria = null) |
|
243 | |||
244 | /** |
||
245 | * @得到城市 |
||
246 | * @license http://www.blags.org/ |
||
247 | * @created :2010年05月21日 20时40分 |
||
248 | * @copyright 1997-2010 The Martin Group |
||
249 | * @author Martin <[email protected]> |
||
250 | * @param null $criteria |
||
251 | * @param bool $id_as_key |
||
252 | * @return array |
||
253 | */ |
||
254 | View Code Duplication | public function &getObjects($criteria = null, $id_as_key = false) |
|
296 | |||
297 | /** |
||
298 | * @得到类别列表 |
||
299 | * @license http://www.blags.org/ |
||
300 | * @created :2010年05月30日 20时48分 |
||
301 | * @copyright 1997-2010 The Martin Group |
||
302 | * @author Martin <[email protected]> |
||
303 | * */ |
||
304 | View Code Duplication | public function GetList() |
|
315 | } |
||
316 |
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.