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 |
||
| 29 | class Stats extends AbstractAPI |
||
| 30 | { |
||
| 31 | const API_DEVICE = 'https://api.weixin.qq.com/shakearound/statistics/device'; |
||
| 32 | const API_DEVICE_LIST = 'https://api.weixin.qq.com/shakearound/statistics/devicelist'; |
||
| 33 | const API_PAGE = 'https://api.weixin.qq.com/shakearound/statistics/page'; |
||
| 34 | const API_PAGE_LIST = 'https://api.weixin.qq.com/shakearound/statistics/pagelist'; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Fetch statistics data by deviceId. |
||
| 38 | * |
||
| 39 | * @param array $deviceIdentifier |
||
| 40 | * @param int $beginDate (Unix timestamp) |
||
| 41 | * @param int $endDate (Unix timestamp) |
||
| 42 | * |
||
| 43 | * @return \EasyWeChat\Support\Collection |
||
| 44 | */ |
||
| 45 | 1 | View Code Duplication | public function deviceSummary(array $deviceIdentifier, $beginDate, $endDate) |
| 55 | |||
| 56 | /** |
||
| 57 | * Fetch all devices statistics data by date. |
||
| 58 | * |
||
| 59 | * @param int $timestamp |
||
| 60 | * @param int $pageIndex |
||
| 61 | * |
||
| 62 | * @return \EasyWeChat\Support\Collection |
||
| 63 | */ |
||
| 64 | 1 | View Code Duplication | public function batchDeviceSummary($timestamp, $pageIndex) |
| 73 | |||
| 74 | /** |
||
| 75 | * Fetch statistics data by pageId. |
||
| 76 | * |
||
| 77 | * @param int $pageId |
||
| 78 | * @param int $beginDate (Unix timestamp) |
||
| 79 | * @param int $endDate (Unix timestamp) |
||
| 80 | * |
||
| 81 | * @return \EasyWeChat\Support\Collection |
||
| 82 | */ |
||
| 83 | 1 | View Code Duplication | public function pageSummary($pageId, $beginDate, $endDate) |
| 93 | |||
| 94 | /** |
||
| 95 | * Fetch all pages statistics data by date. |
||
| 96 | * |
||
| 97 | * @param int $timestamp |
||
| 98 | * @param int $pageIndex |
||
| 99 | * |
||
| 100 | * @return \EasyWeChat\Support\Collection |
||
| 101 | */ |
||
| 102 | 1 | View Code Duplication | public function batchPageSummary($timestamp, $pageIndex) |
| 111 | } |
||
| 112 |