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 |
||
| 5 | class BlogTopics extends Api |
||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Get all the blog topcis |
||
| 10 | * |
||
| 11 | * @param array $params Optional parameters ['name','slug','limit','offset'] |
||
| 12 | * @return \Fungku\HubSpot\Http\Response |
||
| 13 | */ |
||
| 14 | public function all($params = []) |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Search a topic by the query. $query will match name and slug partially |
||
| 26 | * |
||
| 27 | * @link http://developers.hubspot.com/docs/methods/blog/v3/search-blog-topics |
||
| 28 | * |
||
| 29 | * @param string $query Search query |
||
| 30 | * @param array $params Array of optional parameters ['name','slug','limit', 'offset', 'active', 'blog'] |
||
| 31 | * @return \Fungku\HubSpot\Http\Response |
||
| 32 | */ |
||
| 33 | View Code Duplication | public function search($query, $params = []) |
|
| 43 | |||
| 44 | /** |
||
| 45 | * @param int $id |
||
| 46 | * @return \Fungku\HubSpot\Http\Response |
||
| 47 | */ |
||
| 48 | public function getById($id) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Create a new blog topic. |
||
| 57 | * |
||
| 58 | * @param string $name Name of the topic |
||
| 59 | * @param array $params Optional Parameters. |
||
| 60 | * @return \Fungku\HubSpot\Http\Response |
||
| 61 | */ |
||
| 62 | View Code Duplication | public function create($name, $params = []) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * Update a blog topic. |
||
| 75 | * |
||
| 76 | * @param int $id The blog topic id. |
||
| 77 | * @param array $params The blog topic fields to update. |
||
| 78 | * @return \Fungku\HubSpot\Http\Response |
||
| 79 | */ |
||
| 80 | View Code Duplication | public function update($id, $params = []) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * Delete a blog topic. |
||
| 91 | * |
||
| 92 | * @param int $id |
||
| 93 | * @return \Fungku\HubSpot\Http\Response |
||
| 94 | */ |
||
| 95 | public function delete($id) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Group blog topics |
||
| 104 | * |
||
| 105 | * @param array $topicIds Array of topic ids |
||
| 106 | * @param string $groupedTopicName New name of the group |
||
| 107 | * @return \Fungku\HubSpot\Http\Response |
||
| 108 | */ |
||
| 109 | public function merge($topicIds, $groupedTopicName) |
||
| 120 | } |
||
| 121 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.