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 |
||
9 | class TemplateApi extends BaseApi |
||
10 | { |
||
11 | /** |
||
12 | * 设置所属行业 |
||
13 | * |
||
14 | * @param int $industry_id1 [公众号模板消息所属行业编号] |
||
15 | * @param int $industry_id2 [公众号模板消息所属行业编号] |
||
16 | * |
||
17 | * @return bool|array |
||
18 | */ |
||
19 | View Code Duplication | public function apiSetIndustry($industry_id1, $industry_id2) |
|
36 | |||
37 | /** |
||
38 | * 获得模板ID |
||
39 | * |
||
40 | * @param String $template_id_short [公众号模板消息所属行业编号] |
||
41 | * |
||
42 | * @return bool|array |
||
43 | */ |
||
44 | View Code Duplication | public function apiAddTemplate($template_id_short) |
|
60 | |||
61 | /** |
||
62 | * 发送模板消息 |
||
63 | * |
||
64 | * @param string $touser [OPENID] |
||
65 | * @param string $template_id [模板ID] |
||
66 | * @param string $url [跳转url] |
||
67 | * @param array $data [模板参数] |
||
68 | * |
||
69 | * @return int [msgId] |
||
70 | * |
||
71 | */ |
||
72 | public function send($touser, $template_id, $url, $data = []) |
||
93 | } |
||
94 |
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.