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 Staff extends AbstractAPI |
||
11 | { |
||
12 | const API_LISTS = 'https://qyapi.weixin.qq.com/cgi-bin/kf/list'; |
||
13 | const API_MESSAGE_SEND = 'https://qyapi.weixin.qq.com/cgi-bin/kf/send'; |
||
14 | |||
15 | //用户类型 |
||
16 | const USER_TYPE_STAFF = 'kf'; // 客服 |
||
17 | const USER_TYPE_USERID = 'userid'; // 客户UserId |
||
18 | const USER_TYPE_OPENID = 'openid'; // 客户OpenId |
||
19 | |||
20 | //客服类型 |
||
21 | const STAFF_TYPE_INTERNAL = 'internal'; // 内部 |
||
22 | const STAFF_TYPE_EXTERNAL = 'external'; // 外部 |
||
23 | |||
24 | /** |
||
25 | * List all staffs. |
||
26 | * |
||
27 | * @param string|null $type |
||
28 | * |
||
29 | * @return \EntWeChat\Support\Collection |
||
30 | */ |
||
31 | View Code Duplication | public function lists($type = null) |
|
39 | |||
40 | /** |
||
41 | * Get message builder. |
||
42 | * |
||
43 | * @param \EntWeChat\Message\AbstractMessage|string $message |
||
44 | * |
||
45 | * @throws \EntWeChat\Core\Exceptions\InvalidArgumentException |
||
46 | * |
||
47 | * @return \EntWeChat\Staff\MessageBuilder |
||
48 | */ |
||
49 | public function message($message) |
||
55 | |||
56 | /** |
||
57 | * Send a message. |
||
58 | * |
||
59 | * @param string|array $message |
||
60 | * |
||
61 | * @return \EntWeChat\Support\Collection |
||
62 | */ |
||
63 | public function send($message) |
||
67 | } |
||
68 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.