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 |
||
10 | class Tag extends AbstractAPI |
||
11 | { |
||
12 | const API_GET = 'https://qyapi.weixin.qq.com/cgi-bin/tag/list'; |
||
13 | const API_CREATE = 'https://qyapi.weixin.qq.com/cgi-bin/tag/create'; |
||
14 | const API_UPDATE = 'https://qyapi.weixin.qq.com/cgi-bin/tag/update'; |
||
15 | const API_DELETE = 'https://qyapi.weixin.qq.com/cgi-bin/tag/delete'; |
||
16 | const API_MEMBER_BATCH_TAG = 'https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers'; |
||
17 | const API_MEMBER_BATCH_UNTAG = 'https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers'; |
||
18 | const API_USERS_OF_TAG = 'https://qyapi.weixin.qq.com/cgi-bin/tag/get'; |
||
19 | |||
20 | /** |
||
21 | * Create tag. |
||
22 | * |
||
23 | * @param string $name |
||
24 | * @param null $tagI |
||
|
|||
25 | * |
||
26 | * @return int |
||
27 | */ |
||
28 | View Code Duplication | public function create($name, $tagId = null) |
|
37 | |||
38 | /** |
||
39 | * List all tags. |
||
40 | * |
||
41 | * @return array |
||
42 | */ |
||
43 | public function lists() |
||
47 | |||
48 | /** |
||
49 | * Update a tag name. |
||
50 | * |
||
51 | * @param int $tagId |
||
52 | * @param string $name |
||
53 | * |
||
54 | * @return bool |
||
55 | */ |
||
56 | View Code Duplication | public function update($tagId, $name) |
|
65 | |||
66 | /** |
||
67 | * Delete tag. |
||
68 | * |
||
69 | * @param int $tagId |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | View Code Duplication | public function delete($tagId) |
|
81 | |||
82 | /** |
||
83 | * Get users from a tag. |
||
84 | * |
||
85 | * @param string $tagId |
||
86 | * |
||
87 | * @return int |
||
88 | */ |
||
89 | public function usersOfTag($tagId) |
||
95 | |||
96 | /** |
||
97 | * Batch tag users. |
||
98 | * |
||
99 | * @param $tagId |
||
100 | * @param array $userIds |
||
101 | * @param array $partyIds |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | View Code Duplication | public function batchTagUsers($tagId, array $userIds = [], array $partyIds = []) |
|
115 | |||
116 | /** |
||
117 | * Untag users from a tag. |
||
118 | * |
||
119 | * @param $tagId |
||
120 | * @param array $userIds |
||
121 | * @param array $partyIds |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | View Code Duplication | public function batchUntagUsers($tagId, array $userIds = [], array $partyIds = []) |
|
135 | } |
||
136 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.