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 |
||
31 | class Cloudlinux |
||
32 | { |
||
33 | private $login = ''; |
||
34 | private $key = ''; |
||
35 | public $prefix = 'registration.'; |
||
36 | public $encoding = 'utf-8'; // utf-8 / UTF-8 |
||
37 | public $apiType = 'rest'; |
||
38 | public $sslverify = false; |
||
39 | public $xmlOptions = []; |
||
40 | public $xmlUrl = 'https://cln.cloudlinux.com/clweb/xmlrpc'; |
||
41 | public $restUrl = 'https://cln.cloudlinux.com/api/'; |
||
42 | public $restOptions = []; |
||
43 | /** |
||
44 | * @var \XML_RPC2_Client |
||
45 | */ |
||
46 | public $xmlClient; |
||
47 | public $response; |
||
48 | |||
49 | /** |
||
50 | * Cloudlinux::__construct() |
||
51 | * |
||
52 | * @param string $login API Login Name |
||
53 | * @param string $key API Key |
||
54 | * @param string $apiType API type to use, can be 'rest' or 'xml' |
||
55 | */ |
||
56 | 1 | public function __construct($login, $key, $apiType = 'rest') { |
|
72 | |||
73 | /** |
||
74 | * automatic authToken generator |
||
75 | * |
||
76 | * @return false|string the authToken |
||
77 | */ |
||
78 | 1 | public function authToken() { |
|
82 | |||
83 | /** |
||
84 | * getcurlpage() |
||
85 | * gets a webpage via curl and returns the response. |
||
86 | * also it sets a mozilla type agent. |
||
87 | * @param string $url the url of the page you want |
||
88 | * @param string $postfields postfields in the format of "v1=10&v2=20&v3=30" |
||
|
|||
89 | * @param string|array $options |
||
90 | * @return string the webpage |
||
91 | */ |
||
92 | 1 | public function getcurlpage($url) { |
|
105 | |||
106 | public function log($level, $text, $line = '', $file = '') { |
||
112 | |||
113 | /** |
||
114 | * Return system information about several Cloudlinux services |
||
115 | * |
||
116 | * @return array array of system information |
||
117 | */ |
||
118 | 1 | public function status() { |
|
122 | |||
123 | /** |
||
124 | * Will return information about what kind of license types are available for registration and what types are already used by current account. |
||
125 | * @param string $ipAddress ip address to check |
||
126 | * @return array returns an array with available(int[]) list of types that can be used to register new IP license, and owned(int[]) list of types that already registered(owned) by this account |
||
127 | */ |
||
128 | 1 | public function availability($ipAddress) { |
|
132 | |||
133 | /** |
||
134 | * Check if IP license is registered by any customer. |
||
135 | * |
||
136 | * @param string $ipAddress ip address to check |
||
137 | * @return false|array Will return list of registered license types or empty list if provided IP is not registered yet. |
||
138 | */ |
||
139 | 1 | public function check($ipAddress) { |
|
147 | |||
148 | /** |
||
149 | * Check if IP license was registered by any customer. Arguments: |
||
150 | * |
||
151 | * @param string $ipAddress ip address to remove |
||
152 | * @param bool $checkAll True will search for any type of license. False only for types 1 or 2 |
||
153 | * @throws XmlRpcException for critical errors |
||
154 | * @return false|array (list<int>): List of registered license types or empty list if no license found |
||
155 | */ |
||
156 | 1 | public function isLicensed($ipAddress, $checkAll = true) { |
|
162 | /** |
||
163 | * Check if IP license was registered by any customer. Arguments: |
||
164 | * |
||
165 | * @throws XmlRpcException for critical errors |
||
166 | * @param string $ipAddress ip address to remove |
||
167 | * @param bool $checkAll True will search for any type of license. False only for types 1 or 2 |
||
168 | * @return false|array (list<int>): List of registered license types or empty list if no license found |
||
169 | */ |
||
170 | 1 | View Code Duplication | public function xmlIsLicensed($ipAddress, $checkAll = true) { |
181 | |||
182 | /** |
||
183 | * Will register IP based license for authorized user. |
||
184 | * |
||
185 | * @param string $ipAddress ip address to registger |
||
186 | * @param int $type IP license type (1,2 or 16) |
||
187 | * @return array On success response returns information about created or already registered license. ip(string) type(int) license type (1,2,16) registered(boolean) true if server was registered in CLN with this license (CLN licenses only). created(string) license creation time |
||
188 | */ |
||
189 | public function register($ipAddress, $type) { |
||
193 | |||
194 | /** |
||
195 | * Will remove IP based license from authorized user licenses. |
||
196 | * |
||
197 | * @param string $ipAddress ip address to remove licenses on |
||
198 | * @param int $type optional license type. If empty, will remove licenses with all types |
||
199 | * @return bool |
||
200 | */ |
||
201 | public function restRemove($ipAddress, $type = 0) { |
||
208 | |||
209 | /** |
||
210 | * Will remove IP based license from authorized user licenses. |
||
211 | * |
||
212 | * @param string $ipAddress ip address to remove licenses on |
||
213 | * @param int $type optional license type. If empty or 0, will remove licenses with all types |
||
214 | * @return bool|int |
||
215 | */ |
||
216 | public function remove($ipAddress, $type = 0) { |
||
222 | |||
223 | /** |
||
224 | * Remove IP licenses with specified type for customer. Also unregisters from CLN server associated with IP. |
||
225 | * or |
||
226 | * Remove IP licenses with specified type for customer. Also unregisters from CLN server associated with IP. |
||
227 | * @param string $ipAddress ip address to remove |
||
228 | * @param int $type optional parameter to specify the type of license to remove (1,2, or 16) or 0 for all |
||
229 | * @return bool|int 0 on success, -1 on error, Error will be returned also if account have no licenses for provided IP. |
||
230 | */ |
||
231 | public function removeLicense($ipAddress, $type = 0) { |
||
242 | |||
243 | /** |
||
244 | * Return all IP licenses owned by authorized user. |
||
245 | * |
||
246 | * The normal response will look something like: |
||
247 | * [ |
||
248 | * 'success': true, |
||
249 | * 'data': [ |
||
250 | * [ |
||
251 | * 'created': '2017-05-05T16:19-0400', |
||
252 | * 'ip': '66.45.240.186', |
||
253 | * 'registered': true, |
||
254 | * 'type': 1 |
||
255 | * ], [ |
||
256 | * 'created': '2016-10-14T10:42-0400', |
||
257 | * 'ip': '131.153.38.228', |
||
258 | * 'registered': false, |
||
259 | * 'type': 1 |
||
260 | * ], |
||
261 | * ..... |
||
262 | * |
||
263 | * @return false|array an array of licenses each one containing these fields: ip(string) ype(int) license type (1,2,16) registered(boolean) true if server was registered in CLN with this license (CLN licenses only). created(string) license creation time |
||
264 | */ |
||
265 | 1 | public function restList() { |
|
275 | |||
276 | /** |
||
277 | * Return list of all IP licenses owned by authorized user |
||
278 | * |
||
279 | * @throws XmlRpcException for critical errors |
||
280 | * @return false|array (list<structure>): List of structures or empty list. Each structure contains keys: IP(string) TYPE(int) license type REGISTERED(boolean) True if server was registered in CLN with this license |
||
281 | */ |
||
282 | 1 | View Code Duplication | public function reconcile() { |
293 | |||
294 | /** |
||
295 | * alias function to get a list of licenses |
||
296 | * |
||
297 | * @return false|array |
||
298 | */ |
||
299 | 1 | public function licenseList() { |
|
305 | |||
306 | /** |
||
307 | * Register new IP license. |
||
308 | * |
||
309 | * @param string $ipAddress IP Address |
||
310 | * @param integer $type license type (1,2 or 16) |
||
311 | * @throws XmlRpcException for critical errors |
||
312 | * @return false|integer 0 on success, -1 on error |
||
313 | */ |
||
314 | public function license($ipAddress, $type) { |
||
328 | } |
||
329 | |||
330 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.