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()){ |
|
73 | |||
74 | /** |
||
75 | * @inheritdoc |
||
76 | * @param string $server |
||
77 | */ |
||
78 | 1 | public function setServer($server) { |
|
83 | |||
84 | /** |
||
85 | * @inheritdoc |
||
86 | */ |
||
87 | 1 | public function getAPIUrl() { |
|
90 | |||
91 | /** |
||
92 | * @inheritdoc |
||
93 | * Retrieves stored token based on passed in Credentials |
||
94 | */ |
||
95 | 2 | public function setCredentials(array $credentials){ |
|
105 | |||
106 | /** |
||
107 | * @inheritdoc |
||
108 | */ |
||
109 | 1 | public function setToken(\stdClass $token){ |
|
114 | |||
115 | /** |
||
116 | * @inheritdoc |
||
117 | */ |
||
118 | 2 | public function getToken(){ |
|
121 | |||
122 | /** |
||
123 | * @inheritdoc |
||
124 | */ |
||
125 | 1 | public function getCredentials(){ |
|
128 | |||
129 | /** |
||
130 | * @inheritdoc |
||
131 | */ |
||
132 | 1 | public function getServer() { |
|
135 | |||
136 | /** |
||
137 | * @inheritdoc |
||
138 | */ |
||
139 | 1 | public function authenticated(){ |
|
142 | |||
143 | /** |
||
144 | * Register the defined EntryPoints in SDK, located in src/EntryPoint/registry.php file |
||
145 | * @throws EntryPointException |
||
146 | */ |
||
147 | 1 | protected function registerSDKEntryPoints(){ |
|
153 | |||
154 | /** |
||
155 | * @param $funcName |
||
156 | * @param $className |
||
157 | * @return bool |
||
|
|||
158 | * @throws EntryPointException |
||
159 | */ |
||
160 | 2 | public function registerEntryPoint($funcName, $className){ |
|
169 | |||
170 | /** |
||
171 | * Generates the EntryPoint objects based on a Method name that was called |
||
172 | * @param $name |
||
173 | * @param $params |
||
174 | * @return mixed |
||
175 | * @throws EntryPointException |
||
176 | */ |
||
177 | 2 | public function __call($name, $params){ |
|
192 | |||
193 | /** |
||
194 | * @inheritdoc |
||
195 | * @throws AuthenticationException - When Login request fails |
||
196 | */ |
||
197 | 1 | View Code Duplication | public function login() { |
209 | |||
210 | /** |
||
211 | * @inheritdoc |
||
212 | * @throws AuthenticationException - When Refresh Request fails |
||
213 | */ |
||
214 | 1 | public function refreshToken(){ |
|
236 | |||
237 | /** |
||
238 | * @inheritdoc |
||
239 | * @throws AuthenticationException - When logout request fails |
||
240 | */ |
||
241 | 1 | View Code Duplication | public function logout(){ |
256 | |||
257 | /** |
||
258 | * @inheritdoc |
||
259 | * @param \stdClass $token |
||
260 | */ |
||
261 | 1 | public static function storeToken($token, $client_id) { |
|
265 | |||
266 | /** |
||
267 | * @inheritdoc |
||
268 | */ |
||
269 | 1 | public static function getStoredToken($client_id) { |
|
272 | |||
273 | /** |
||
274 | * @inheritdoc |
||
275 | */ |
||
276 | 1 | public static function removeStoredToken($client_id) { |
|
280 | |||
281 | } |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.