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 DealProperties extends Resource |
||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Get a Deal Property. |
||
| 10 | * |
||
| 11 | * Returns a JSON object representing the definition for a given deal property. |
||
| 12 | * |
||
| 13 | * @see http://developers.hubspot.com/docs/methods/deals/get_deal_property |
||
| 14 | * |
||
| 15 | * @param string $name The name of the property. |
||
| 16 | * @return \SevenShores\Hubspot\Http\Response |
||
| 17 | */ |
||
| 18 | function get($name) |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Create a deal property. |
||
| 27 | * |
||
| 28 | * Create a property on every deal object to store a specific piece of data. In the example below, |
||
| 29 | * we want to store an invoice number on a separate field on deals. |
||
| 30 | * |
||
| 31 | * @see https://developers.hubspot.com/docs/methods/deals/create_deal_property |
||
| 32 | * |
||
| 33 | * @param array $property |
||
| 34 | * @return \SevenShores\Hubspot\Http\Response |
||
| 35 | */ |
||
| 36 | function create($property) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Update a deal property. |
||
| 47 | * |
||
| 48 | * Update a specified deal property. |
||
| 49 | * |
||
| 50 | * @see http://developers.hubspot.com/docs/methods/deals/update_deal_property |
||
| 51 | * |
||
| 52 | * @param string $name |
||
| 53 | * @param array $property |
||
| 54 | * @return \SevenShores\Hubspot\Http\Response |
||
| 55 | */ |
||
| 56 | function update($name, $property) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Delete a deal property. |
||
| 68 | * |
||
| 69 | * @see https://developers.hubspot.com/docs/methods/deals/delete_deal_property |
||
| 70 | * |
||
| 71 | * @param string $name |
||
| 72 | * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response |
||
| 73 | */ |
||
| 74 | public function delete($name) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Returns all of deal properties |
||
| 82 | * |
||
| 83 | * @see https://developers.hubspot.com/docs/methods/deals/get_deal_properties |
||
| 84 | * |
||
| 85 | * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response |
||
| 86 | */ |
||
| 87 | public function all() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Create a new deal property group to gather like deal-level data. |
||
| 95 | * @param array $group Defines the group and any properties within it. |
||
| 96 | * |
||
| 97 | * @see https://developers.hubspot.com/docs/methods/deals/create_deal_property_group |
||
| 98 | * |
||
| 99 | * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response |
||
| 100 | */ |
||
| 101 | public function createGroup($group) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Update a previously created deal property group. |
||
| 110 | * @param string $groupName The API name of the property group that you will be updating. |
||
| 111 | * @param array $group Defines the property group and any properties within it. |
||
| 112 | * |
||
| 113 | * @see https://developers.hubspot.com/docs/methods/deals/update_deal_property_group |
||
| 114 | * |
||
| 115 | * @return \SevenShores\Hubspot\Http\Response |
||
| 116 | */ |
||
| 117 | function updateGroup($groupName, $group) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Delete an existing deal property group. |
||
| 129 | * @param string $groupName The API name of the property group that you will be deleting. |
||
| 130 | * |
||
| 131 | * @see https://developers.hubspot.com/docs/methods/deals/delete_deal_property_group |
||
| 132 | * |
||
| 133 | * @return \SevenShores\Hubspot\Http\Response |
||
| 134 | */ |
||
| 135 | function deleteGroup($groupName) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Get a deals property group by name |
||
| 144 | * |
||
| 145 | * @param string $groupName The API name of the property group that you will be returned. |
||
| 146 | * @param bool $includeProperties If true returns all of the properties for each deal property group. |
||
| 147 | * |
||
| 148 | * @see https://developers.hubspot.com/docs/methods/deals/get_deal_property_group |
||
| 149 | * |
||
| 150 | * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response |
||
| 151 | */ |
||
| 152 | View Code Duplication | public function getGroup($groupName, $includeProperties = false) |
|
| 164 | |||
| 165 | /** |
||
| 166 | * Returns all of the deal property groups for a given portal. |
||
| 167 | * @param bool $includeProperties If true returns all of the properties for each deal property group. |
||
| 168 | * |
||
| 169 | * @see https://developers.hubspot.com/docs/methods/deals/get_deal_property_groups |
||
| 170 | * |
||
| 171 | * @return \SevenShores\Hubspot\Http\Response |
||
| 172 | */ |
||
| 173 | View Code Duplication | function getAllGroups($includeProperties = false) |
|
| 185 | } |
||
| 186 |
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.