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 |
||
| 30 | class Device extends AbstractAPI |
||
| 31 | { |
||
| 32 | const API_DEVICE_APPLYID = 'https://api.weixin.qq.com/shakearound/device/applyid'; |
||
| 33 | const API_DEVICE_APPLYSTATUS = 'https://api.weixin.qq.com/shakearound/device/applystatus'; |
||
| 34 | const API_DEVICE_UPDATE = 'https://api.weixin.qq.com/shakearound/device/update'; |
||
| 35 | const API_DEVICE_BINDLOCATION = 'https://api.weixin.qq.com/shakearound/device/bindlocation'; |
||
| 36 | const API_DEVICE_SEARCH = 'https://api.weixin.qq.com/shakearound/device/search'; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Apply device ids. |
||
| 40 | * |
||
| 41 | * @param int $quantity |
||
| 42 | * @param string $reason |
||
| 43 | * @param string $comment |
||
| 44 | * @param int $poiId |
||
| 45 | * |
||
| 46 | * @return \EasyWeChat\Support\Collection |
||
| 47 | */ |
||
| 48 | 1 | public function apply($quantity, $reason, $comment = '', $poiId = null) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Get audit status. |
||
| 68 | * |
||
| 69 | * @param int $applyId |
||
| 70 | * |
||
| 71 | * @return \EasyWeChat\Support\Collection |
||
| 72 | */ |
||
| 73 | 1 | public function getStatus($applyId) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Update a device comment. |
||
| 84 | * |
||
| 85 | * @param array $deviceIdentifier |
||
| 86 | * @param string $comment |
||
| 87 | * |
||
| 88 | * @return \EasyWeChat\Support\Collection |
||
| 89 | */ |
||
| 90 | 1 | public function update(array $deviceIdentifier, $comment) |
|
| 99 | |||
| 100 | /** |
||
| 101 | * Bind location for device. |
||
| 102 | * |
||
| 103 | * @param array $deviceIdentifier |
||
| 104 | * @param int $poiId |
||
| 105 | * @param int $type |
||
| 106 | * @param string $poiAppid |
||
| 107 | * |
||
| 108 | * @return \EasyWeChat\Support\Collection |
||
| 109 | * |
||
| 110 | * @throws InvalidArgumentException |
||
| 111 | */ |
||
| 112 | 1 | public function bindLocation(array $deviceIdentifier, $poiId, $type = 1, $poiAppid = null) |
|
| 129 | |||
| 130 | /** |
||
| 131 | * Fetch batch of devices by deviceIds. |
||
| 132 | * |
||
| 133 | * @param array $deviceIdentifiers |
||
| 134 | * |
||
| 135 | * @return \EasyWeChat\Support\Collection |
||
| 136 | */ |
||
| 137 | 1 | public function fetchByIds(array $deviceIdentifiers) |
|
| 146 | |||
| 147 | /** |
||
| 148 | * Pagination to fetch batch of devices. |
||
| 149 | * |
||
| 150 | * @param int $lastSeen |
||
| 151 | * @param int $count |
||
| 152 | * |
||
| 153 | * @return \EasyWeChat\Support\Collection |
||
| 154 | */ |
||
| 155 | 1 | View Code Duplication | public function pagination($lastSeen, $count) |
| 165 | |||
| 166 | /** |
||
| 167 | * Fetch batch of devices by applyId. |
||
| 168 | * |
||
| 169 | * @param int $applyId |
||
| 170 | * @param int $lastSeen |
||
| 171 | * @param int $count |
||
| 172 | * |
||
| 173 | * @return \EasyWeChat\Support\Collection |
||
| 174 | */ |
||
| 175 | 1 | View Code Duplication | public function fetchByApplyId($applyId, $lastSeen, $count) |
| 186 | |||
| 187 | /** |
||
| 188 | * Fetch batch of devices. |
||
| 189 | * |
||
| 190 | * @param array $params |
||
| 191 | * |
||
| 192 | * @return \EasyWeChat\Support\Collection |
||
| 193 | */ |
||
| 194 | 3 | private function fetch($params) |
|
| 198 | } |
||
| 199 |