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_GET = 'https://api.weixin.qq.com/cgi-bin/groups/get'; |
||
| 31 | const API_CREATE = 'https://api.weixin.qq.com/cgi-bin/groups/create'; |
||
| 32 | const API_UPDATE = 'https://api.weixin.qq.com/cgi-bin/groups/update'; |
||
| 33 | const API_DELETE = 'https://api.weixin.qq.com/cgi-bin/groups/delete'; |
||
| 34 | const API_USER_GROUP_ID = 'https://api.weixin.qq.com/cgi-bin/groups/getid'; |
||
| 35 | const API_MEMBER_UPDATE = 'https://api.weixin.qq.com/cgi-bin/groups/members/update'; |
||
| 36 | const API_MEMBER_BATCH_UPDATE = 'https://api.weixin.qq.com/cgi-bin/groups/members/batchupdate'; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Create group. |
||
| 40 | * |
||
| 41 | * @param string $name |
||
| 42 | * |
||
| 43 | * @return int |
||
| 44 | */ |
||
| 45 | 1 | View Code Duplication | public function create($name) |
| 53 | |||
| 54 | /** |
||
| 55 | * List all groups. |
||
| 56 | * |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | 1 | public function lists() |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Update a group name. |
||
| 66 | * |
||
| 67 | * @param int $groupId |
||
| 68 | * @param string $name |
||
| 69 | * |
||
| 70 | * @return bool |
||
| 71 | */ |
||
| 72 | 1 | View Code Duplication | public function update($groupId, $name) |
| 83 | |||
| 84 | /** |
||
| 85 | * Delete group. |
||
| 86 | * |
||
| 87 | * @param int $groupId |
||
| 88 | * |
||
| 89 | * @return bool |
||
| 90 | */ |
||
| 91 | 1 | View Code Duplication | public function delete($groupId) |
| 99 | |||
| 100 | /** |
||
| 101 | * Get user group. |
||
| 102 | * |
||
| 103 | * @param string $openId |
||
| 104 | * |
||
| 105 | * @return int |
||
| 106 | */ |
||
| 107 | 1 | public function userGroup($openId) |
|
| 113 | |||
| 114 | /** |
||
| 115 | * Move user to a group. |
||
| 116 | * |
||
| 117 | * @param string $openId |
||
| 118 | * @param int $groupId |
||
| 119 | * |
||
| 120 | * @return bool |
||
| 121 | */ |
||
| 122 | 1 | public function moveUser($openId, $groupId) |
|
| 131 | |||
| 132 | /** |
||
| 133 | * Batch move users to a group. |
||
| 134 | * |
||
| 135 | * @param array $openIds |
||
| 136 | * @param int $groupId |
||
| 137 | * |
||
| 138 | * @return bool |
||
| 139 | */ |
||
| 140 | 1 | public function moveUsers(array $openIds, $groupId) |
|
| 149 | } |
||
| 150 |