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 Tag extends AbstractAPI |
||
| 29 | { |
||
| 30 | const API_GET = 'https://api.weixin.qq.com/cgi-bin/tags/get'; |
||
| 31 | const API_CREATE = 'https://api.weixin.qq.com/cgi-bin/tags/create'; |
||
| 32 | const API_UPDATE = 'https://api.weixin.qq.com/cgi-bin/tags/update'; |
||
| 33 | const API_DELETE = 'https://api.weixin.qq.com/cgi-bin/tags/delete'; |
||
| 34 | const API_USER_TAGS = 'https://api.weixin.qq.com/cgi-bin/tags/getidlist'; |
||
| 35 | const API_MEMBER_BATCH_TAG = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging'; |
||
| 36 | const API_MEMBER_BATCH_UNTAG = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging'; |
||
| 37 | const API_USERS_OF_TAG = 'https://api.weixin.qq.com/cgi-bin/user/tag/get'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Create tag. |
||
| 41 | * |
||
| 42 | * @param string $name |
||
| 43 | * |
||
| 44 | * @return int |
||
| 45 | */ |
||
| 46 | 1 | View Code Duplication | public function create($name) |
| 54 | |||
| 55 | /** |
||
| 56 | * List all tags. |
||
| 57 | * |
||
| 58 | * @return array |
||
| 59 | */ |
||
| 60 | 1 | public function lists() |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Update a tag name. |
||
| 67 | * |
||
| 68 | * @param int $tagId |
||
| 69 | * @param string $name |
||
| 70 | * |
||
| 71 | * @return bool |
||
| 72 | */ |
||
| 73 | 1 | public function update($tagId, $name) |
|
| 84 | |||
| 85 | /** |
||
| 86 | * Delete tag. |
||
| 87 | * |
||
| 88 | * @param int $tagId |
||
| 89 | * |
||
| 90 | * @return bool |
||
| 91 | */ |
||
| 92 | 1 | public function delete($tagId) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Get user tags. |
||
| 103 | * |
||
| 104 | * @param string $openId |
||
| 105 | * |
||
| 106 | * @return int |
||
| 107 | */ |
||
| 108 | 1 | public function userTags($openId) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Get users from a tag. |
||
| 117 | * |
||
| 118 | * @param string $openId |
||
|
|
|||
| 119 | * |
||
| 120 | * @return int |
||
| 121 | */ |
||
| 122 | 1 | public function usersOfTag($tagId) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * Batch tag users. |
||
| 131 | * |
||
| 132 | * @param array $openIds |
||
| 133 | * @param int $tagid |
||
| 134 | * |
||
| 135 | * @return bool |
||
| 136 | */ |
||
| 137 | 1 | View Code Duplication | public function batchTagUsers(array $openIds, $tagId) |
| 146 | |||
| 147 | /** |
||
| 148 | * Untag users from a tag. |
||
| 149 | * |
||
| 150 | * @param array $openIds |
||
| 151 | * @param int $tagid |
||
| 152 | * |
||
| 153 | * @return bool |
||
| 154 | */ |
||
| 155 | 1 | View Code Duplication | public function batchUntagUsers(array $openIds, $tagId) |
| 164 | } |
||
| 165 |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.