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