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 Webhooks extends Resource |
||
| 6 | {
|
||
| 7 | /** |
||
| 8 | * Get list of subscriptions. |
||
| 9 | * |
||
| 10 | * @param int $app_id |
||
| 11 | * @return \SevenShores\Hubspot\Http\Response |
||
| 12 | */ |
||
| 13 | function getSubscription($app_id) |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Create a new subscription. |
||
| 22 | * |
||
| 23 | * @param int $app_id |
||
| 24 | * @param array $subscription |
||
| 25 | * @return \SevenShores\Hubspot\Http\Response |
||
| 26 | */ |
||
| 27 | View Code Duplication | function createSubscription($app_id, $subscription) |
|
| 35 | |||
| 36 | /** |
||
| 37 | * Update a subscription. |
||
| 38 | * |
||
| 39 | * @param int $app_id |
||
| 40 | * @param int $subscription_id |
||
| 41 | * @param array $subscription |
||
| 42 | * @return \SevenShores\Hubspot\Http\Response |
||
| 43 | */ |
||
| 44 | View Code Duplication | function updateSubscription($app_id, $subscription_id, $subscription) |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Delete a subscription. |
||
| 55 | * |
||
| 56 | * @param int $app_id |
||
| 57 | * @param int $subscription_id |
||
| 58 | * @return \SevenShores\Hubspot\Http\Response |
||
| 59 | */ |
||
| 60 | function deleteSubscription($app_id, $subscription_id) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Get webhook settings. |
||
| 69 | * |
||
| 70 | * @param int $app_id |
||
| 71 | * @return \SevenShores\Hubspot\Http\Response |
||
| 72 | */ |
||
| 73 | function viewSettings($app_id) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Update webhook settings. |
||
| 82 | * |
||
| 83 | * @param int $app_id |
||
| 84 | * @param array $settings |
||
| 85 | * @return \SevenShores\Hubspot\Http\Response |
||
| 86 | */ |
||
| 87 | View Code Duplication | function updateSettings($app_id, $settings) |
|
| 95 | |||
| 96 | } |
||
| 97 |
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.