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 |
||
9 | class GroupsApi extends BaseApi |
||
10 | { |
||
11 | /** |
||
12 | * 创建用户组. |
||
13 | * |
||
14 | * @param string $name 分组名 30字符以内 |
||
15 | * |
||
16 | * @return array id 分组ID , name 分组名. |
||
17 | */ |
||
18 | public function create($name) |
||
34 | |||
35 | /** |
||
36 | * 查询分组 |
||
37 | * |
||
38 | * @return array 所有分组信息 如没有分组返回false. |
||
39 | */ |
||
40 | public function get() |
||
48 | |||
49 | /** |
||
50 | * 查询用户所在分组 |
||
51 | * |
||
52 | * @param string $openid 用户ID |
||
53 | * |
||
54 | * @return int. |
||
|
|||
55 | */ |
||
56 | View Code Duplication | public function getid($openid) |
|
70 | |||
71 | /** |
||
72 | * 修改分组名 |
||
73 | * |
||
74 | * @param int|string $id 分组ID,$name 分组名 |
||
75 | * |
||
76 | * @return bool. |
||
77 | */ |
||
78 | public function update($id, $name) |
||
94 | |||
95 | /** |
||
96 | * 删除指定分组 |
||
97 | * |
||
98 | * @param int $id 分组ID |
||
99 | * |
||
100 | * @return bool. 注:删除成功时返回的是 '' ,删除失败时返回的是false,(包括分组ID不是数字或分组ID已经不存在) |
||
101 | */ |
||
102 | View Code Duplication | public function delete($id) |
|
118 | |||
119 | /** |
||
120 | * 移动用户到指定分组 |
||
121 | * |
||
122 | * @param string $openid 用户ID,to_groupid 指定分组ID |
||
123 | * |
||
124 | * @return bool. |
||
125 | */ |
||
126 | |||
127 | View Code Duplication | public function moveUser($openid, $to_groupid) |
|
141 | |||
142 | /** |
||
143 | * 批量移动用户到指定分组 |
||
144 | * |
||
145 | * @param array $openid_list 用户ID,to_groupid 指定分组ID |
||
146 | * |
||
147 | * @return bool. 注:其中批量移动时,其中有一个用户的id是错的,那么其他的也不会移动,若用户已经在目标组里那么返回值也是true |
||
148 | */ |
||
149 | View Code Duplication | public function MoveUserlistGroup($openid_list, $to_groupid) |
|
163 | } |
||
164 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.