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 |
||
| 16 | abstract class AbstractClient implements ClientInterface { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Array of Statically Bound Tokens for SDK Clients |
||
| 20 | * - Allows for reinstating objects in multiple areas, without needing to Sign-in |
||
| 21 | * - Allows for multiple client_id's to be used between SDK Clients |
||
| 22 | * |
||
| 23 | * @var array = array( |
||
| 24 | * $client_id => $token |
||
| 25 | * ) |
||
| 26 | */ |
||
| 27 | protected static $_STORED_TOKENS = array(); |
||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * The configured server domain name/url on the SDK Client |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $server = ''; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The API Url configured on the SDK Client |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $apiURL = ''; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The full token object returned by the Login method |
||
| 44 | * @var \stdClass |
||
| 45 | */ |
||
| 46 | protected $token; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Array of OAuth Creds to be used by SDK Client |
||
| 50 | * @var array |
||
| 51 | */ |
||
| 52 | protected $credentials = array(); |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Token expiration time |
||
| 56 | * @var |
||
| 57 | */ |
||
| 58 | protected $expiration; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * The list of registered EntryPoints |
||
| 62 | * @var array |
||
| 63 | */ |
||
| 64 | protected $entryPoints = array(); |
||
| 65 | |||
| 66 | 1 | public function __construct($server = '',array $credentials = array()){ |
|
| 77 | |||
| 78 | /** |
||
| 79 | * @inheritdoc |
||
| 80 | * @param string $server |
||
| 81 | */ |
||
| 82 | 1 | public function setServer($server) { |
|
| 87 | |||
| 88 | /** |
||
| 89 | * @inheritdoc |
||
| 90 | */ |
||
| 91 | 1 | public function getAPIUrl() { |
|
| 94 | |||
| 95 | /** |
||
| 96 | * @inheritdoc |
||
| 97 | * Retrieves stored token based on passed in Credentials |
||
| 98 | */ |
||
| 99 | 2 | public function setCredentials(array $credentials){ |
|
| 109 | |||
| 110 | /** |
||
| 111 | * @inheritdoc |
||
| 112 | */ |
||
| 113 | 1 | public function setToken(\stdClass $token){ |
|
| 118 | |||
| 119 | /** |
||
| 120 | * @inheritdoc |
||
| 121 | */ |
||
| 122 | 2 | public function getToken(){ |
|
| 125 | |||
| 126 | /** |
||
| 127 | * @inheritdoc |
||
| 128 | */ |
||
| 129 | 1 | public function getCredentials(){ |
|
| 132 | |||
| 133 | /** |
||
| 134 | * @inheritdoc |
||
| 135 | */ |
||
| 136 | 1 | public function getServer() { |
|
| 139 | |||
| 140 | /** |
||
| 141 | * @inheritdoc |
||
| 142 | */ |
||
| 143 | 1 | public function authenticated(){ |
|
| 146 | |||
| 147 | /** |
||
| 148 | * Register the defined EntryPoints in SDK, located in src/EntryPoint/registry.php file |
||
| 149 | * @throws EntryPointException |
||
| 150 | */ |
||
| 151 | 1 | protected function registerSDKEntryPoints(){ |
|
| 157 | |||
| 158 | /** |
||
| 159 | * @param $funcName |
||
| 160 | * @param $className |
||
| 161 | * @return bool |
||
|
|
|||
| 162 | * @throws EntryPointException |
||
| 163 | */ |
||
| 164 | 2 | public function registerEntryPoint($funcName, $className){ |
|
| 173 | |||
| 174 | /** |
||
| 175 | * Generates the EntryPoint objects based on a Method name that was called |
||
| 176 | * @param $name |
||
| 177 | * @param $params |
||
| 178 | * @return mixed |
||
| 179 | * @throws EntryPointException |
||
| 180 | */ |
||
| 181 | 2 | public function __call($name, $params){ |
|
| 196 | |||
| 197 | /** |
||
| 198 | * @inheritdoc |
||
| 199 | * @throws AuthenticationException - When Login request fails |
||
| 200 | */ |
||
| 201 | View Code Duplication | public function login() { |
|
| 213 | |||
| 214 | /** |
||
| 215 | * @inheritdoc |
||
| 216 | * @throws AuthenticationException - When Refresh Request fails |
||
| 217 | */ |
||
| 218 | public function refreshToken(){ |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @inheritdoc |
||
| 238 | * @throws AuthenticationException - When logout request fails |
||
| 239 | */ |
||
| 240 | View Code Duplication | public function logout(){ |
|
| 254 | |||
| 255 | /** |
||
| 256 | * @inheritdoc |
||
| 257 | * @param \stdClass $token |
||
| 258 | */ |
||
| 259 | 1 | public static function storeToken($token, $client_id) { |
|
| 263 | |||
| 264 | /** |
||
| 265 | * @inheritdoc |
||
| 266 | */ |
||
| 267 | 1 | public static function getStoredToken($client_id) { |
|
| 270 | |||
| 271 | /** |
||
| 272 | * @inheritdoc |
||
| 273 | */ |
||
| 274 | 1 | public static function removeStoredToken($client_id) { |
|
| 278 | |||
| 279 | } |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.