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 OAuth2 extends Resource |
||
| 6 | { |
||
| 7 | protected $endpoint = 'https://api.hubapi.com/oauth/v1'; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Initiate an Integration with OAuth 2.0 |
||
| 11 | * |
||
| 12 | * @param string $clientId The Client ID of your app. |
||
| 13 | * @param string $redirectURI The URL that you want the visitor redirected to after granting access to your app. For security reasons, this URL must use https. |
||
| 14 | * @param array $scopesArray A set of scopes that your app will need access to. |
||
| 15 | * @return \SevenShores\Hubspot\Http\Response |
||
| 16 | */ |
||
| 17 | function getAuthUrl($clientId, $redirectURI, $scopesArray=array()) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Get OAuth 2.0 Access Token and Refresh Tokens by using a one-time code |
||
| 37 | * |
||
| 38 | * @param string $clientId The Client ID of your app. |
||
| 39 | * @param string $clientSecret The Client Secret of your app. |
||
| 40 | * @param string $redirectURI The redirect URI that was used when the user authorized your app. This must exactly match the redirect_uri used when initiating the OAuth 2.0 connection. |
||
| 41 | * @param string $tokenCode The code parameter returned to your redirect URI when the user authorized your app. Or a refresh token. |
||
| 42 | * @return \SevenShores\Hubspot\Http\Response |
||
| 43 | */ |
||
| 44 | View Code Duplication | function getTokensByCode($clientId, $clientSecret, $redirectURI, $tokenCode) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * Get OAuth 2.0 Access Token and Refresh Tokens by using a refresh token |
||
| 61 | * Note: Contrary to HubSpot documentation, $redirectURI is NOT required. |
||
| 62 | * |
||
| 63 | * @param string $clientId The Client ID of your app. |
||
| 64 | * @param string $clientSecret The Client Secret of your app. |
||
| 65 | * @param string $refreshToken The refresh token. |
||
| 66 | * @return \SevenShores\Hubspot\Http\Response |
||
| 67 | */ |
||
| 68 | View Code Duplication | function getTokensByRefresh($clientId, $clientSecret, $refreshToken) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Get Information for OAuth 2.0 Access Token |
||
| 84 | * |
||
| 85 | * @param int $token The access token that you want to get the information for. |
||
| 86 | * @return \SevenShores\Hubspot\Http\Response |
||
| 87 | */ |
||
| 88 | function getAccessTokenInfo($token) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Get Information for OAuth 2.0 Refresh Token |
||
| 95 | * |
||
| 96 | * @param int $token The refresh token that you want to get the information for. |
||
| 97 | * @return \SevenShores\Hubspot\Http\Response |
||
| 98 | */ |
||
| 99 | function getRefreshTokenInfo($token) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Delete OAuth 2.0 Refresh Token |
||
| 106 | * |
||
| 107 | * @param int $token The refresh token that you want to delete. |
||
| 108 | * @return \SevenShores\Hubspot\Http\Response |
||
| 109 | */ |
||
| 110 | function deleteRefreshToken($token) |
||
| 114 | |||
| 115 | } |
||
| 116 |
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.