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 |
||
| 30 | class Staff extends AbstractAPI |
||
| 31 | { |
||
| 32 | const API_LISTS = 'https://api.weixin.qq.com/cgi-bin/customservice/getkflist'; |
||
| 33 | const API_ONLINE = 'https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist'; |
||
| 34 | const API_DELETE = 'https://api.weixin.qq.com/customservice/kfaccount/del'; |
||
| 35 | const API_UPDATE = 'https://api.weixin.qq.com/customservice/kfaccount/update'; |
||
| 36 | const API_CREATE = 'https://api.weixin.qq.com/customservice/kfaccount/add'; |
||
| 37 | const API_INVITE_BIND = 'https://api.weixin.qq.com/customservice/kfaccount/inviteworker'; |
||
| 38 | const API_MESSAGE_SEND = 'https://api.weixin.qq.com/cgi-bin/message/custom/send'; |
||
| 39 | const API_AVATAR_UPLOAD = 'https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg'; |
||
| 40 | const API_RECORDS = 'https://api.weixin.qq.com/customservice/msgrecord/getrecord'; |
||
| 41 | const API_MSG_LIST = 'https://api.weixin.qq.com/customservice/msgrecord/getmsglist'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * List all staffs. |
||
| 45 | * |
||
| 46 | * @return \EasyWeChat\Support\Collection |
||
| 47 | 1 | */ |
|
| 48 | public function lists() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * List all online staffs. |
||
| 55 | * |
||
| 56 | * @return \EasyWeChat\Support\Collection |
||
| 57 | 1 | */ |
|
| 58 | public function onlines() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Create a staff. |
||
| 65 | * |
||
| 66 | * @param string $account |
||
| 67 | * @param string $nickname |
||
| 68 | * |
||
| 69 | * @return \EasyWeChat\Support\Collection |
||
| 70 | 1 | */ |
|
| 71 | View Code Duplication | public function create($account, $nickname) |
|
| 80 | |||
| 81 | /** |
||
| 82 | * Update a staff. |
||
| 83 | * |
||
| 84 | * @param string $account |
||
| 85 | * @param string $nickname |
||
| 86 | * |
||
| 87 | * @return \EasyWeChat\Support\Collection |
||
| 88 | 1 | */ |
|
| 89 | View Code Duplication | public function update($account, $nickname) |
|
| 98 | |||
| 99 | /** |
||
| 100 | * Delete a staff. |
||
| 101 | * |
||
| 102 | * @param string $account |
||
| 103 | * |
||
| 104 | * @return \EasyWeChat\Support\Collection |
||
| 105 | */ |
||
| 106 | public function delete($account) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Invite a staff. |
||
| 125 | * |
||
| 126 | * @param string $account |
||
| 127 | * @param string $wechatId |
||
| 128 | * |
||
| 129 | * @return \EasyWeChat\Support\Collection |
||
| 130 | 1 | */ |
|
| 131 | public function invite($account, $wechatId) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Set staff avatar. |
||
| 143 | * |
||
| 144 | * @param string $account |
||
| 145 | * @param string $path |
||
| 146 | * |
||
| 147 | * @return \EasyWeChat\Support\Collection |
||
| 148 | 1 | */ |
|
| 149 | public function avatar($account, $path) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Get message builder. |
||
| 156 | * |
||
| 157 | * @param \EasyWeChat\Message\AbstractMessage|string $message |
||
| 158 | * |
||
| 159 | * @return \EasyWeChat\Staff\MessageBuilder |
||
| 160 | * |
||
| 161 | * @throws \EasyWeChat\Core\Exceptions\InvalidArgumentException |
||
| 162 | */ |
||
| 163 | public function message($message) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Send a message. |
||
| 172 | * |
||
| 173 | * @param string|array $message |
||
| 174 | * |
||
| 175 | * @return \EasyWeChat\Support\Collection |
||
| 176 | */ |
||
| 177 | public function send($message) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Get staff session history. |
||
| 184 | * |
||
| 185 | * @param int $startTime |
||
| 186 | * @param int $endTime |
||
| 187 | * @param int $page |
||
| 188 | * @param int $pageSize |
||
| 189 | * |
||
| 190 | * @return \EasyWeChat\Support\Collection |
||
| 191 | */ |
||
| 192 | View Code Duplication | public function records($startTime, $endTime, $page = 1, $pageSize = 10) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * 获取聊天记录. |
||
| 206 | * |
||
| 207 | * @param int $startTime |
||
| 208 | * @param int $endTime |
||
| 209 | * @param int $msgid |
||
| 210 | * @param int $number |
||
| 211 | * |
||
| 212 | * @return \EasyWeChat\Support\Collection |
||
| 213 | */ |
||
| 214 | View Code Duplication | public function msglist($startTime, $endTime, $msgid = 1, $number = 10000) |
|
| 225 | } |
||
| 226 |