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 |
||
| 13 | abstract class AbstractClient implements ClientInterface { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Array of Statically Bound Tokens for SDK Clients |
||
| 17 | * - Allows for reinstating objects in multiple areas, without needing to Sign-in |
||
| 18 | * - Allows for multiple client_id's to be used between SDK Clients |
||
| 19 | * |
||
| 20 | * @var array = array( |
||
| 21 | * $client_id => $token |
||
| 22 | * ) |
||
| 23 | */ |
||
| 24 | protected static $_STORED_TOKENS = array(); |
||
| 25 | |||
| 26 | |||
| 27 | /** |
||
| 28 | * The configured server domain name/url on the SDK Client |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | protected $server = ''; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The API Url configured on the SDK Client |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $apiURL = ''; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The full token object returned by the Login method |
||
| 41 | * @var \stdClass |
||
| 42 | */ |
||
| 43 | protected $token; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Array of OAuth Creds to be used by SDK Client |
||
| 47 | * @var array |
||
| 48 | */ |
||
| 49 | protected $credentials = array(); |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Token expiration time |
||
| 53 | * @var |
||
| 54 | */ |
||
| 55 | protected $expiration; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The list of registered EntryPoints |
||
| 59 | * @var array |
||
| 60 | */ |
||
| 61 | protected $entryPoints = array(); |
||
| 62 | |||
| 63 | public function __construct($server = '',array $credentials = array()){ |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @inheritdoc |
||
| 77 | * @param string $server |
||
| 78 | */ |
||
| 79 | public function setServer($server) { |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @inheritdoc |
||
| 87 | */ |
||
| 88 | public function getAPIUrl() { |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @inheritdoc |
||
| 94 | * Retrieves stored token based on passed in Credentials |
||
| 95 | */ |
||
| 96 | public function setCredentials(array $credentials){ |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @inheritdoc |
||
| 107 | */ |
||
| 108 | public function setToken(\stdClass $token){ |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @inheritdoc |
||
| 116 | */ |
||
| 117 | public function getToken(){ |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @inheritdoc |
||
| 123 | */ |
||
| 124 | public function getCredentials(){ |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @inheritdoc |
||
| 130 | */ |
||
| 131 | public function getServer() { |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @inheritdoc |
||
| 137 | */ |
||
| 138 | public function authenticated(){ |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Register the defined EntryPoints in SDK, located in src/EntryPoint/registry.php file |
||
| 144 | * @throws EntryPointException |
||
| 145 | */ |
||
| 146 | protected function registerSDKEntryPoints(){ |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @param $funcName |
||
| 155 | * @param $className |
||
| 156 | * @return bool |
||
|
|
|||
| 157 | * @throws EntryPointException |
||
| 158 | */ |
||
| 159 | public function registerEntryPoint($funcName, $className){ |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Generates the EntryPoint objects based on a Method name that was called |
||
| 171 | * @param $name |
||
| 172 | * @param $params |
||
| 173 | * @return mixed |
||
| 174 | * @throws EntryPointException |
||
| 175 | */ |
||
| 176 | public function __call($name, $params){ |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @inheritdoc |
||
| 194 | * @throws AuthenticationException - When Login request fails |
||
| 195 | */ |
||
| 196 | View Code Duplication | public function login() { |
|
| 208 | |||
| 209 | /** |
||
| 210 | * @inheritdoc |
||
| 211 | * @throws AuthenticationException - When Refresh Request fails |
||
| 212 | */ |
||
| 213 | public function refreshToken(){ |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @inheritdoc |
||
| 233 | * @throws AuthenticationException - When logout request fails |
||
| 234 | */ |
||
| 235 | View Code Duplication | public function logout(){ |
|
| 249 | |||
| 250 | /** |
||
| 251 | * @inheritdoc |
||
| 252 | * @param \stdClass $token |
||
| 253 | */ |
||
| 254 | public static function storeToken($token, $client_id) { |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @inheritdoc |
||
| 261 | */ |
||
| 262 | public static function getStoredToken($client_id) { |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @inheritdoc |
||
| 268 | */ |
||
| 269 | public static function removeStoredToken($client_id) { |
||
| 273 | |||
| 274 | } |
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.