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 | const API_DEVICE = 'https://api.weixin.qq.com/shakearound/statistics/device'; |
||
31 | const API_DEVICE_LIST = 'https://api.weixin.qq.com/shakearound/statistics/devicelist'; |
||
32 | const API_PAGE = 'https://api.weixin.qq.com/shakearound/statistics/page'; |
||
33 | const API_PAGE_LIST = 'https://api.weixin.qq.com/shakearound/statistics/pagelist'; |
||
34 | |||
35 | /** |
||
36 | * Fetch statistics data by device_id. |
||
37 | * |
||
38 | * @param array $device_identifier |
||
39 | * @param int $begin_date (Unix timestamp) |
||
40 | * @param int $end_date (Unix timestamp) |
||
41 | * |
||
42 | * @return \EasyWeChat\Support\Collection |
||
43 | */ |
||
44 | View Code Duplication | public function deviceSummary(array $device_identifier, $begin_date, $end_date) |
|
54 | |||
55 | /** |
||
56 | * Fetch all devices statistics data by date. |
||
57 | * |
||
58 | * @param int $timestamp |
||
59 | * @param int $page_index |
||
60 | * |
||
61 | * @return \EasyWeChat\Support\Collection |
||
62 | */ |
||
63 | View Code Duplication | public function batchDeviceSummary($timestamp, $page_index) |
|
72 | |||
73 | /** |
||
74 | * Fetch statistics data by page_id. |
||
75 | * |
||
76 | * @param int $page_id |
||
77 | * @param int $begin_date (Unix timestamp) |
||
78 | * @param int $end_date (Unix timestamp) |
||
79 | * |
||
80 | * @return \EasyWeChat\Support\Collection |
||
81 | */ |
||
82 | View Code Duplication | public function pageSummary($page_id, $begin_date, $end_date) |
|
91 | |||
92 | /** |
||
93 | * Fetch all pages statistics data by date. |
||
94 | * |
||
95 | * @param int $timestamp |
||
96 | * @param int $page_index |
||
97 | * |
||
98 | * @return \EasyWeChat\Support\Collection |
||
99 | */ |
||
100 | View Code Duplication | public function batchPageSummary($timestamp, $page_index) |
|
109 | } |
||
110 |