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 |
||
| 28 | class Shelf extends Base implements ShelfInterface |
||
| 29 | { |
||
| 30 | |||
| 31 | const API_ADD = 'https://api.weixin.qq.com/merchant/shelf/add'; |
||
| 32 | const API_DELETE = 'https://api.weixin.qq.com/merchant/shelf/del'; |
||
| 33 | const API_UPDATE = 'https://api.weixin.qq.com/merchant/shelf/mod'; |
||
| 34 | const API_LISTS = 'https://api.weixin.qq.com/merchant/shelf/getall'; |
||
| 35 | const API_GET_BY_ID = 'https://api.weixin.qq.com/merchant/shelf/getbyid'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * 添加货架 |
||
| 39 | * |
||
| 40 | * @param $shelfData |
||
| 41 | * @param $shelfBanner |
||
| 42 | * @param $shelfName |
||
| 43 | * @return int |
||
| 44 | * @throws ShopsException |
||
| 45 | */ |
||
| 46 | View Code Duplication | public function add($shelfData,$shelfBanner,$shelfName) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * 删除货架 |
||
| 73 | * |
||
| 74 | * @param int $shelfId |
||
| 75 | * @return bool |
||
| 76 | * @throws ShopsException |
||
| 77 | */ |
||
| 78 | public function delete($shelfId) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * 修改货架 |
||
| 87 | * |
||
| 88 | * @param array|callable $shelfData |
||
| 89 | * @param $shelfId |
||
| 90 | * @param $shelfBanner |
||
| 91 | * @param $shelfName |
||
| 92 | * @return bool |
||
| 93 | * @throws ShopsException |
||
| 94 | */ |
||
| 95 | View Code Duplication | public function update($shelfData,$shelfId,$shelfBanner,$shelfName) |
|
| 117 | |||
| 118 | /** |
||
| 119 | * 获取所有货架 |
||
| 120 | * |
||
| 121 | * @return array |
||
| 122 | * @throws ShopsException |
||
| 123 | */ |
||
| 124 | public function lists() |
||
| 130 | |||
| 131 | /** |
||
| 132 | * 根据货架ID获取货架信息 |
||
| 133 | * |
||
| 134 | * @param $shelfId |
||
| 135 | * @return array |
||
| 136 | * @throws ShopsException |
||
| 137 | */ |
||
| 138 | public function getById($shelfId) |
||
| 144 | } |