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 |
||
31 | class Comment extends AbstractAPI |
||
32 | { |
||
33 | const API_OPEN_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/open'; |
||
34 | const API_CLOSE_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/close'; |
||
35 | const API_LIST_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/list'; |
||
36 | const API_MARK_ELECT = 'https://api.weixin.qq.com/cgi-bin/comment/markelect'; |
||
37 | const API_UNMARK_ELECT = 'https://api.weixin.qq.com/cgi-bin/comment/unmarkelect'; |
||
38 | const API_DELETE_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/delete'; |
||
39 | const API_REPLY_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/reply/add'; |
||
40 | const API_DELETE_REPLY = 'https://api.weixin.qq.com/cgi-bin/comment/reply/delete'; |
||
41 | |||
42 | /** |
||
43 | * Open article comment. |
||
44 | * |
||
45 | * @param int $dataId |
||
46 | * @param int $index |
||
47 | * |
||
48 | * @return \EasyWeChat\Support\Collection |
||
49 | */ |
||
50 | 1 | public function open($dataId, $index = null) |
|
59 | |||
60 | /** |
||
61 | * Close comment. |
||
62 | * |
||
63 | * @param int $dataId |
||
64 | * @param int $index |
||
65 | * |
||
66 | * @return \EasyWeChat\Support\Collection |
||
67 | */ |
||
68 | 1 | public function close($dataId, $index = null) |
|
77 | |||
78 | /** |
||
79 | * Get article comments. |
||
80 | * |
||
81 | * @param int $dataId |
||
82 | * @param int $index |
||
83 | * @param int $begin |
||
84 | * @param int $count |
||
85 | * @param int $type |
||
86 | * |
||
87 | * @return \EasyWeChat\Support\Collection |
||
88 | */ |
||
89 | 1 | public function lists($dataId, $index, $begin, $count, $type = 0) |
|
101 | |||
102 | /** |
||
103 | * Mark elect comment. |
||
104 | * |
||
105 | * @param int $dataId |
||
106 | * @param int $index |
||
107 | * @param int $commentId |
||
108 | * |
||
109 | * @return \EasyWeChat\Support\Collection |
||
110 | */ |
||
111 | 1 | View Code Duplication | public function markElect($dataId, $index, $commentId) |
121 | |||
122 | /** |
||
123 | * Unmark elect comment. |
||
124 | * |
||
125 | * @param int $dataId |
||
126 | * @param int $index |
||
127 | * @param int $commentId |
||
128 | * |
||
129 | * @return \EasyWeChat\Support\Collection |
||
130 | */ |
||
131 | 1 | View Code Duplication | public function unmarkElect($dataId, $index, $commentId) |
141 | |||
142 | /** |
||
143 | * Delete comment. |
||
144 | * |
||
145 | * @param int $dataId |
||
146 | * @param int $index |
||
147 | * @param int $commentId |
||
148 | * |
||
149 | * @return \EasyWeChat\Support\Collection |
||
150 | */ |
||
151 | 1 | View Code Duplication | public function delete($dataId, $index, $commentId) |
161 | |||
162 | /** |
||
163 | * Reply to a comment. |
||
164 | * |
||
165 | * @param int $dataId |
||
166 | * @param int $index |
||
167 | * @param int $commentId |
||
168 | * @param string $content |
||
169 | * |
||
170 | * @return \EasyWeChat\Support\Collection |
||
171 | */ |
||
172 | 1 | View Code Duplication | public function reply($dataId, $index, $commentId, $content) |
183 | |||
184 | /** |
||
185 | * Delete a reply. |
||
186 | * |
||
187 | * @param int $dataId |
||
188 | * @param int $index |
||
189 | * @param int $commentId |
||
190 | * |
||
191 | * @return \EasyWeChat\Support\Collection |
||
192 | */ |
||
193 | 1 | View Code Duplication | public function deleteReply($dataId, $index, $commentId) |
203 | } |
||
204 |