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