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 |
||
| 29 | class Group extends AbstractAPI |
||
| 30 | { |
||
| 31 | const API_ADD = 'https://api.weixin.qq.com/shakearound/device/group/add'; |
||
| 32 | const API_UPDATE = 'https://api.weixin.qq.com/shakearound/device/group/update'; |
||
| 33 | const API_DELETE = 'https://api.weixin.qq.com/shakearound/device/group/delete'; |
||
| 34 | const API_GET_LIST = 'https://api.weixin.qq.com/shakearound/device/group/getlist'; |
||
| 35 | const API_GET_DETAIL = 'https://api.weixin.qq.com/shakearound/device/group/getdetail'; |
||
| 36 | const API_ADD_DEVICE = 'https://api.weixin.qq.com/shakearound/device/group/adddevice'; |
||
| 37 | const API_DELETE_DEVICE = 'https://api.weixin.qq.com/shakearound/device/group/deletedevice'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Add device group. |
||
| 41 | * |
||
| 42 | * @param string $name |
||
| 43 | * |
||
| 44 | * @return \EasyWeChat\Support\Collection |
||
| 45 | */ |
||
| 46 | 1 | View Code Duplication | public function add($name) |
| 54 | |||
| 55 | /** |
||
| 56 | * Update a device group name. |
||
| 57 | * |
||
| 58 | * @param int $groupId |
||
| 59 | * @param string $name |
||
| 60 | * |
||
| 61 | * @return \EasyWeChat\Support\Collection |
||
| 62 | */ |
||
| 63 | 1 | View Code Duplication | public function update($groupId, $name) |
| 72 | |||
| 73 | /** |
||
| 74 | * Delete device group. |
||
| 75 | * |
||
| 76 | * @param int $groupId |
||
| 77 | * |
||
| 78 | * @return \EasyWeChat\Support\Collection |
||
| 79 | */ |
||
| 80 | 1 | public function delete($groupId) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * List all device groups. |
||
| 91 | * |
||
| 92 | * @param int $begin |
||
| 93 | * @param int $count |
||
| 94 | * |
||
| 95 | * @return \EasyWeChat\Support\Collection |
||
| 96 | */ |
||
| 97 | 1 | public function lists($begin, $count) |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Get details of a device group. |
||
| 109 | * |
||
| 110 | * @param int $groupId |
||
| 111 | * @param int $begin |
||
| 112 | * @param int $count |
||
| 113 | * |
||
| 114 | * @return \EasyWeChat\Support\Collection |
||
| 115 | */ |
||
| 116 | 1 | public function getDetails($groupId, $begin, $count) |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Add one or more devices to a device group. |
||
| 129 | * |
||
| 130 | * @param int $groupId |
||
| 131 | * @param array $deviceIdentifiers |
||
| 132 | * |
||
| 133 | * @return \EasyWeChat\Support\Collection |
||
| 134 | */ |
||
| 135 | 1 | public function addDevice($groupId, array $deviceIdentifiers) |
|
| 144 | |||
| 145 | /** |
||
| 146 | * Remove one or more devices from a device group. |
||
| 147 | * |
||
| 148 | * @param int $groupId |
||
| 149 | * @param array $deviceIdentifiers |
||
| 150 | * |
||
| 151 | * @return \EasyWeChat\Support\Collection |
||
| 152 | */ |
||
| 153 | 1 | public function removeDevice($groupId, array $deviceIdentifiers) |
|
| 162 | } |
||
| 163 |