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 |
||
| 29 | class Staff extends AbstractAPI |
||
| 30 | { |
||
| 31 | const API_LISTS = 'https://api.weixin.qq.com/cgi-bin/customservice/getkflist'; |
||
| 32 | const API_ONLINE = 'https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist'; |
||
| 33 | const API_DELETE = 'https://api.weixin.qq.com/customservice/kfaccount/del'; |
||
| 34 | const API_UPDATE = 'https://api.weixin.qq.com/customservice/kfaccount/update'; |
||
| 35 | const API_CREATE = 'https://api.weixin.qq.com/customservice/kfaccount/add'; |
||
| 36 | const API_INVITE_BIND = 'https://api.weixin.qq.com/customservice/kfaccount/inviteworker'; |
||
| 37 | const API_MESSAGE_SEND = 'https://api.weixin.qq.com/cgi-bin/message/custom/send'; |
||
| 38 | const API_AVATAR_UPLOAD = 'https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg'; |
||
| 39 | const API_RECORDS = 'https://api.weixin.qq.com/customservice/msgrecord/getrecord'; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * List all staffs. |
||
| 43 | * |
||
| 44 | * @return \EasyWeChat\Support\Collection |
||
| 45 | */ |
||
| 46 | 1 | public function lists() |
|
| 50 | |||
| 51 | /** |
||
| 52 | * List all online staffs. |
||
| 53 | * |
||
| 54 | * @return \EasyWeChat\Support\Collection |
||
| 55 | */ |
||
| 56 | 1 | public function onlines() |
|
| 60 | |||
| 61 | /** |
||
| 62 | * Create a staff. |
||
| 63 | * |
||
| 64 | * @param string $account |
||
| 65 | * @param string $nickname |
||
| 66 | * |
||
| 67 | * @return \EasyWeChat\Support\Collection |
||
| 68 | */ |
||
| 69 | 1 | View Code Duplication | public function create($account, $nickname) |
| 78 | |||
| 79 | /** |
||
| 80 | * Update a staff. |
||
| 81 | * |
||
| 82 | * @param string $account |
||
| 83 | * @param string $nickname |
||
| 84 | * |
||
| 85 | * @return \EasyWeChat\Support\Collection |
||
| 86 | */ |
||
| 87 | 1 | View Code Duplication | public function update($account, $nickname) |
| 96 | |||
| 97 | /** |
||
| 98 | * Delete a staff. |
||
| 99 | * |
||
| 100 | * @param string $account |
||
| 101 | * |
||
| 102 | * @return \EasyWeChat\Support\Collection |
||
| 103 | */ |
||
| 104 | public function delete($account) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Invite a staff. |
||
| 123 | * |
||
| 124 | * @param string $account |
||
| 125 | * @param string $wechatId |
||
| 126 | * |
||
| 127 | * @return \EasyWeChat\Support\Collection |
||
| 128 | */ |
||
| 129 | 1 | public function invite($account, $wechatId) |
|
| 138 | |||
| 139 | /** |
||
| 140 | * Set staff avatar. |
||
| 141 | * |
||
| 142 | * @param string $account |
||
| 143 | * @param string $path |
||
| 144 | * |
||
| 145 | * @return \EasyWeChat\Support\Collection |
||
| 146 | */ |
||
| 147 | 1 | public function avatar($account, $path) |
|
| 151 | |||
| 152 | /** |
||
| 153 | * Get message builder. |
||
| 154 | * |
||
| 155 | * @param \EasyWeChat\Message\AbstractMessage|string $message |
||
| 156 | * |
||
| 157 | * @return \EasyWeChat\Staff\MessageBuilder |
||
| 158 | * |
||
| 159 | * @throws \EasyWeChat\Core\Exceptions\InvalidArgumentException |
||
| 160 | */ |
||
| 161 | public function message($message) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Send a message. |
||
| 170 | * |
||
| 171 | * @param string|array $message |
||
| 172 | * |
||
| 173 | * @return \EasyWeChat\Support\Collection |
||
| 174 | */ |
||
| 175 | public function send($message) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Get staff session history. |
||
| 182 | * |
||
| 183 | * @param int $startTime |
||
| 184 | * @param int $endTime |
||
| 185 | * @param int $page |
||
| 186 | * @param int $pageSize |
||
| 187 | * |
||
| 188 | * @return \EasyWeChat\Support\Collection |
||
| 189 | */ |
||
| 190 | public function records($startTime, $endTime, $page = 1, $pageSize = 10) |
||
| 201 | } |
||
| 202 |