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 Page extends AbstractAPI |
||
| 30 | { |
||
| 31 | const API_ADD = 'https://api.weixin.qq.com/shakearound/page/add'; |
||
| 32 | const API_UPDATE = 'https://api.weixin.qq.com/shakearound/page/update'; |
||
| 33 | const API_SEARCH = 'https://api.weixin.qq.com/shakearound/page/search'; |
||
| 34 | const API_DELETE = 'https://api.weixin.qq.com/shakearound/page/delete'; |
||
| 35 | const API_RELATION_SEARCH = 'https://api.weixin.qq.com/shakearound/relation/search'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Add a page. |
||
| 39 | * |
||
| 40 | * @param string $title |
||
| 41 | * @param string $description |
||
| 42 | * @param string $pageUrl |
||
| 43 | * @param string $iconUrl |
||
| 44 | * @param string $comment |
||
| 45 | * |
||
| 46 | * @return \EasyWeChat\Support\Collection |
||
| 47 | */ |
||
| 48 | 1 | View Code Duplication | public function add($title, $description, $pageUrl, $iconUrl, $comment = '') |
| 62 | |||
| 63 | /** |
||
| 64 | * update a page info. |
||
| 65 | * |
||
| 66 | * @param int $pageId |
||
| 67 | * @param string $title |
||
| 68 | * @param string $description |
||
| 69 | * @param string $pageUrl |
||
| 70 | * @param string $iconUrl |
||
| 71 | * @param string $comment |
||
| 72 | * |
||
| 73 | * @return \EasyWeChat\Support\Collection |
||
| 74 | */ |
||
| 75 | 1 | View Code Duplication | public function update($pageId, $title, $description, $pageUrl, $iconUrl, $comment = '') |
| 90 | |||
| 91 | /** |
||
| 92 | * Fetch batch of pages by pageIds. |
||
| 93 | * |
||
| 94 | * @param array $pageIds |
||
| 95 | * |
||
| 96 | * @return \EasyWeChat\Support\Collection |
||
| 97 | */ |
||
| 98 | 1 | View Code Duplication | public function fetchByIds(array $pageIds) |
| 107 | |||
| 108 | /** |
||
| 109 | * Pagination to fetch batch of pages. |
||
| 110 | * |
||
| 111 | * @param int $begin |
||
| 112 | * @param int $count |
||
| 113 | * |
||
| 114 | * @return \EasyWeChat\Support\Collection |
||
| 115 | */ |
||
| 116 | 1 | public function pagination($begin, $count) |
|
| 126 | |||
| 127 | /** |
||
| 128 | * delete a page. |
||
| 129 | * |
||
| 130 | * @param int $pageId |
||
| 131 | * |
||
| 132 | * @return \EasyWeChat\Support\Collection |
||
| 133 | */ |
||
| 134 | 1 | public function delete($pageId) |
|
| 142 | } |
||
| 143 |