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 |
||
28 | class Stats extends AbstractAPI |
||
29 | { |
||
30 | // 获取用户增减数据 |
||
31 | const API_USER_SUMMARY = 'https://api.weixin.qq.com/datacube/getusersummary'; |
||
32 | // 获取累计用户数据 |
||
33 | const API_USER_CUMULATE = 'https://api.weixin.qq.com/datacube/getusercumulate'; |
||
34 | // 获取图文群发每日数据 |
||
35 | const API_ARTICLE_SUMMARY = 'https://api.weixin.qq.com/datacube/getarticlesummary'; |
||
36 | // 获取图文群发总数据 |
||
37 | const API_ARTICLE_TOTAL = 'https://api.weixin.qq.com/datacube/getarticletotal'; |
||
38 | // 获取图文统计数据 |
||
39 | const API_USER_READ_SUMMARY = 'https://api.weixin.qq.com/datacube/getuserread'; |
||
40 | // 获取图文统计分时数据 |
||
41 | const API_USER_READ_HOURLY = 'https://api.weixin.qq.com/datacube/getuserreadhour'; |
||
42 | // 获取图文分享转发数据 |
||
43 | const API_USER_SHARE_SUMMARY = 'https://api.weixin.qq.com/datacube/getusershare'; |
||
44 | // 获取图文分享转发分时数据 |
||
45 | const API_USER_SHARE_HOURLY = 'https://api.weixin.qq.com/datacube/getusersharehour'; |
||
46 | // 获取消息发送概况数据 |
||
47 | const API_UPSTREAM_MSG_SUMMARY = 'https://api.weixin.qq.com/datacube/getupstreammsg'; |
||
48 | // 获取消息分送分时数据 |
||
49 | const API_UPSTREAM_MSG_HOURLY = 'https://api.weixin.qq.com/datacube/getupstreammsghour'; |
||
50 | // 获取消息发送周数据 |
||
51 | const API_UPSTREAM_MSG_WEEKLY = 'https://api.weixin.qq.com/datacube/getupstreammsgweek'; |
||
52 | // 获取消息发送月数据 |
||
53 | const API_UPSTREAM_MSG_MONTHLY = 'https://api.weixin.qq.com/datacube/getupstreammsgmonth'; |
||
54 | // 获取消息发送分布数据 |
||
55 | const API_UPSTREAM_MSG_DIST_SUMMARY = 'https://api.weixin.qq.com/datacube/getupstreammsgdist'; |
||
56 | // 获取消息发送分布周数据 |
||
57 | const API_UPSTREAM_MSG_DIST_WEEKLY = 'https://api.weixin.qq.com/datacube/getupstreammsgdistweek'; |
||
58 | // 获取消息发送分布月数据 |
||
59 | const API_UPSTREAM_MSG_DIST_MONTHLY = 'https://api.weixin.qq.com/datacube/getupstreammsgdistmonth?'; |
||
60 | // 获取接口分析数据 |
||
61 | const API_INTERFACE_SUMMARY = 'https://api.weixin.qq.com/datacube/getinterfacesummary'; |
||
62 | // 获取接口分析分时数据 |
||
63 | const API_INTERFACE_SUMMARY_HOURLY = 'https://api.weixin.qq.com/datacube/getinterfacesummaryhour'; |
||
64 | // 拉取卡券概况数据接口 |
||
65 | const API_CARD_SUMMARY = 'https://api.weixin.qq.com/datacube/getcardbizuininfo'; |
||
66 | // 获取免费券数据接口 |
||
67 | const API_FREE_CARD_SUMMARY = 'https://api.weixin.qq.com/datacube/getcardcardinfo'; |
||
68 | // 拉取会员卡数据接口 |
||
69 | const API_MEMBER_CARD_SUMMARY = 'https://api.weixin.qq.com/datacube/getcardmembercardinfo'; |
||
70 | |||
71 | /** |
||
72 | * 获取用户增减数据. |
||
73 | * |
||
74 | * @param string $from |
||
75 | * @param string $to |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | 1 | public function userSummary($from, $to) |
|
83 | |||
84 | /** |
||
85 | * 获取累计用户数据. |
||
86 | * |
||
87 | * @param string $from |
||
88 | * @param string $to |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | 1 | public function userCumulate($from, $to) |
|
96 | |||
97 | /** |
||
98 | * 获取图文群发每日数据. |
||
99 | * |
||
100 | * @param string $from |
||
101 | * @param string $to |
||
102 | * |
||
103 | * @return array |
||
104 | */ |
||
105 | 1 | public function articleSummary($from, $to) |
|
109 | |||
110 | /** |
||
111 | * 获取图文群发总数据. |
||
112 | * |
||
113 | * @param string $from |
||
114 | * @param string $to |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | 1 | public function articleTotal($from, $to) |
|
122 | |||
123 | /** |
||
124 | * 获取图文统计数据. |
||
125 | * |
||
126 | * @param string $from |
||
127 | * @param string $to |
||
128 | * |
||
129 | * @return array |
||
130 | */ |
||
131 | 1 | public function userReadSummary($from, $to) |
|
135 | |||
136 | /** |
||
137 | * 获取图文统计分时数据. |
||
138 | * |
||
139 | * @param string $from |
||
140 | * @param string $to |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | 1 | public function userReadHourly($from, $to) |
|
148 | |||
149 | /** |
||
150 | * 获取图文分享转发数据. |
||
151 | * |
||
152 | * @param string $from |
||
153 | * @param string $to |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | 1 | public function userShareSummary($from, $to) |
|
161 | |||
162 | /** |
||
163 | * 获取图文分享转发分时数据. |
||
164 | * |
||
165 | * @param string $from |
||
166 | * @param string $to |
||
167 | * |
||
168 | * @return array |
||
169 | */ |
||
170 | 1 | public function userShareHourly($from, $to) |
|
174 | |||
175 | /** |
||
176 | * 获取消息发送概况数据. |
||
177 | * |
||
178 | * @param string $from |
||
179 | * @param string $to |
||
180 | * |
||
181 | * @return array |
||
182 | */ |
||
183 | 1 | public function upstreamMessageSummary($from, $to) |
|
187 | |||
188 | /** |
||
189 | * 获取消息分送分时数据. |
||
190 | * |
||
191 | * @param string $from |
||
192 | * @param string $to |
||
193 | * |
||
194 | * @return array |
||
195 | */ |
||
196 | 1 | public function upstreamMessageHourly($from, $to) |
|
200 | |||
201 | /** |
||
202 | * 获取消息发送周数据. |
||
203 | * |
||
204 | * @param string $from |
||
205 | * @param string $to |
||
206 | * |
||
207 | * @return array |
||
208 | */ |
||
209 | 1 | public function upstreamMessageWeekly($from, $to) |
|
213 | |||
214 | /** |
||
215 | * 获取消息发送月数据. |
||
216 | * |
||
217 | * @param string $from |
||
218 | * @param string $to |
||
219 | * |
||
220 | * @return array |
||
221 | */ |
||
222 | 1 | public function upstreamMessageMonthly($from, $to) |
|
226 | |||
227 | /** |
||
228 | * 获取消息发送分布数据. |
||
229 | * |
||
230 | * @param string $from |
||
231 | * @param string $to |
||
232 | * |
||
233 | * @return array |
||
234 | */ |
||
235 | 1 | public function upstreamMessageDistSummary($from, $to) |
|
239 | |||
240 | /** |
||
241 | * 获取消息发送分布周数据. |
||
242 | * |
||
243 | * @param string $from |
||
244 | * @param string $to |
||
245 | * |
||
246 | * @return array |
||
247 | */ |
||
248 | 1 | public function upstreamMessageDistWeekly($from, $to) |
|
252 | |||
253 | /** |
||
254 | * 获取消息发送分布月数据. |
||
255 | * |
||
256 | * @param string $from |
||
257 | * @param string $to |
||
258 | * |
||
259 | * @return array |
||
260 | */ |
||
261 | 1 | public function upstreamMessageDistMonthly($from, $to) |
|
265 | |||
266 | /** |
||
267 | * 获取接口分析数据. |
||
268 | * |
||
269 | * @param string $from |
||
270 | * @param string $to |
||
271 | * |
||
272 | * @return array |
||
273 | */ |
||
274 | 1 | public function interfaceSummary($from, $to) |
|
278 | |||
279 | /** |
||
280 | * 获取接口分析分时数据. |
||
281 | * |
||
282 | * @param string $from |
||
283 | * @param string $to |
||
284 | * |
||
285 | * @return array |
||
286 | */ |
||
287 | 1 | public function interfaceSummaryHourly($from, $to) |
|
291 | |||
292 | /** |
||
293 | * 拉取卡券概况数据接口. |
||
294 | * |
||
295 | * @param string $from |
||
296 | * @param string $to |
||
297 | * @param int $condSource |
||
298 | * |
||
299 | * @return array |
||
300 | */ |
||
301 | 1 | View Code Duplication | public function cardSummary($from, $to, $condSource = 0) |
309 | |||
310 | /** |
||
311 | * 获取免费券数据接口. |
||
312 | * |
||
313 | * @param string $from |
||
314 | * @param string $to |
||
315 | * @param int $condSource |
||
316 | * @param string $cardId |
||
317 | * |
||
318 | * @return array |
||
319 | */ |
||
320 | 1 | View Code Duplication | public function freeCardSummary($from, $to, $condSource = 0, $cardId = '') |
329 | |||
330 | /** |
||
331 | * 拉取会员卡数据接口. |
||
332 | * |
||
333 | * @param string $from |
||
334 | * @param string $to |
||
335 | * @param int $condSource |
||
336 | * |
||
337 | * @return array |
||
338 | */ |
||
339 | 1 | View Code Duplication | public function memberCardSummary($from, $to, $condSource = 0) |
347 | |||
348 | /** |
||
349 | * 查询数据. |
||
350 | * |
||
351 | * @param string $api |
||
352 | * @param string $from |
||
353 | * @param string $to |
||
354 | * |
||
355 | * @return array |
||
356 | */ |
||
357 | 20 | protected function query($api, $from, $to, array $ext = []) |
|
370 | } |
||
371 |