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 Resource |
||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Get all the blog topcis |
||
| 10 | * |
||
| 11 | * @param array $params Optional parameters ['name','slug','limit','offset'] |
||
| 12 | * @return \SevenShores\Hubspot\Http\Response |
||
| 13 | */ |
||
| 14 | function all($params = []) |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Search a topic by the query. $query will match name and slug partially |
||
| 26 | * |
||
| 27 | * @see 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 \SevenShores\Hubspot\Http\Response |
||
| 32 | */ |
||
| 33 | function search($query, $params = []) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param int $id |
||
| 46 | * @return \SevenShores\Hubspot\Http\Response |
||
| 47 | */ |
||
| 48 | 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 \SevenShores\Hubspot\Http\Response |
||
| 61 | */ |
||
| 62 | View Code Duplication | 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 \SevenShores\Hubspot\Http\Response |
||
| 79 | */ |
||
| 80 | function update($id, $params = []) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Delete a blog topic. |
||
| 91 | * |
||
| 92 | * @param int $id |
||
| 93 | * @return \SevenShores\Hubspot\Http\Response |
||
| 94 | */ |
||
| 95 | 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 \SevenShores\Hubspot\Http\Response |
||
| 108 | */ |
||
| 109 | function merge($topicIds, $groupedTopicName) |
||
| 120 | } |
||
| 121 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.