| Conditions | 60 |
| Paths | 6 |
| Total Lines | 145 |
| Code Lines | 95 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 218 | public function create(Account $account, array $options = []) |
||
| 219 | { |
||
| 220 | if (empty($account->getUser())) { |
||
| 221 | throw ClientExceptions::invalidArgument("You must provide an username to create new account"); |
||
| 222 | } |
||
| 223 | |||
| 224 | if (empty($account->getDomain())) { |
||
| 225 | throw ClientExceptions::invalidArgument("You must provide a domain to create new account"); |
||
| 226 | } |
||
| 227 | |||
| 228 | $params = []; |
||
| 229 | $params['username'] = $account->getUser(); |
||
| 230 | $params['domain'] = $account->getDomain(); |
||
| 231 | !empty($account->getPlanName()) ? $params['plan'] = $account->getPlanName() : null; |
||
| 232 | !empty($options['pkgname']) ? $params['pkgname'] = $options['pkgname'] : null; |
||
| 233 | if (!empty($options['savepkg'])) { |
||
| 234 | if (!in_array(intval($options['savepkg']), [0, 1])) { |
||
| 235 | throw new ClientExceptions("`savepkg` must be either 0 or 1"); |
||
| 236 | } |
||
| 237 | |||
| 238 | $params['savepkg'] = $options['savepkg']; |
||
| 239 | } |
||
| 240 | |||
| 241 | !empty($options['featurelist']) ? $params['featurelist'] = $options['featurelist'] : null; |
||
| 242 | if (!empty($account->getDiskLimit())) { |
||
| 243 | if ($account->getDiskLimit() === -1) { |
||
| 244 | $params['quota'] = 0; |
||
| 245 | } else { |
||
| 246 | $params['quota'] = intval($account->getDiskLimit()); |
||
| 247 | } |
||
| 248 | } |
||
| 249 | |||
| 250 | !empty($account->getPassword()) ? $params['password'] = $account->getPassword() : null; |
||
| 251 | !empty($account->getIpAddress()) ? $params['ip'] = $account->getIpAddress() : null; |
||
| 252 | !empty($account->isCgiEnable()) ? $params['cgi'] = (int)$account->isCgiEnable() : null; |
||
| 253 | !empty($account->isSpamAssassinEnable()) ? |
||
| 254 | $params['spamassassin'] = (int)$account->isSpamAssassinEnable() |
||
| 255 | : null; |
||
| 256 | !empty($account->isFrontPageEnable()) ? $params['frontpage'] = (int)$account->isFrontPageEnable() : null; |
||
| 257 | !empty($account->getShell()) ? $params['hasshell'] = 1 : null; |
||
| 258 | !empty($account->getEmail()) ? $params['contactemail'] = 1 : null; |
||
| 259 | !empty($account->getEmail()) ? $params['contactemail'] = 1 : null; |
||
| 260 | !empty($account->getTheme()) ? $params['cpmod'] = 1 : null; |
||
| 261 | |||
| 262 | if ($account->getMaxFTP() === -1) { |
||
| 263 | $params['maxftp'] = "unlimited"; |
||
| 264 | } elseif ($account->getMaxFTP() > 0) { |
||
| 265 | $params['maxftp'] = intval($account->getMaxFTP()); |
||
| 266 | } |
||
| 267 | |||
| 268 | if ($account->getMaxSQL() === -1) { |
||
| 269 | $params['maxsql'] = "unlimited"; |
||
| 270 | } elseif ($account->getMaxSQL() > 0) { |
||
| 271 | $params['maxsql'] = intval($account->getMaxSQL()); |
||
| 272 | } |
||
| 273 | |||
| 274 | if ($account->getMaxPOP() === -1) { |
||
| 275 | $params['maxpop'] = "unlimited"; |
||
| 276 | } elseif ($account->getMaxPOP() > 0) { |
||
| 277 | $params['maxpop'] = intval($account->getMaxPOP()); |
||
| 278 | } |
||
| 279 | |||
| 280 | if ($account->getMaxMailingList() === -1) { |
||
| 281 | $params['maxlst'] = "unlimited"; |
||
| 282 | } elseif ($account->getMaxMailingList() > 0) { |
||
| 283 | $params['maxlst'] = intval($account->getMaxMailingList()); |
||
| 284 | } |
||
| 285 | |||
| 286 | if ($account->getMaxSubDomain() === -1) { |
||
| 287 | $params['maxsub'] = "unlimited"; |
||
| 288 | } elseif ($account->getMaxSubDomain() > 0) { |
||
| 289 | $params['maxsub'] = intval($account->getMaxSubDomain()); |
||
| 290 | } |
||
| 291 | |||
| 292 | if ($account->getMaxParkedDomains() === -1) { |
||
| 293 | $params['maxpark'] = "unlimited"; |
||
| 294 | } elseif ($account->getMaxParkedDomains() > 0) { |
||
| 295 | $params['maxpark'] = intval($account->getMaxParkedDomains()); |
||
| 296 | } |
||
| 297 | |||
| 298 | if ($account->getMaxAddonDomains() === -1) { |
||
| 299 | $params['maxaddon'] = "unlimited"; |
||
| 300 | } elseif ($account->getMaxAddonDomains() > 0) { |
||
| 301 | $params['maxaddon'] = intval($account->getMaxAddonDomains()); |
||
| 302 | } |
||
| 303 | |||
| 304 | if ($account->getBandwidthLimit() === -1) { |
||
| 305 | $params['bwlimit'] = "unlimited"; |
||
| 306 | } elseif ($account->getBandwidthLimit() > 0) { |
||
| 307 | $params['bwlimit'] = intval($account->getBandwidthLimit()); |
||
| 308 | } |
||
| 309 | |||
| 310 | !empty($options['customip']) ? $params['customip'] = $options['customip'] : null; |
||
| 311 | |||
| 312 | !empty($account->getLanguagePreference()) ? $params['language'] = $account->getLanguagePreference() : null; |
||
| 313 | |||
| 314 | !empty($options['useregns']) ? $params['useregns'] = $options['useregns'] : null; |
||
| 315 | !empty($options['reseller']) ? $params['reseller'] = (int)$options['reseller'] : null; |
||
| 316 | !empty($options['forcedns']) ? $params['forcedns'] = (int)$options['forcedns'] : null; |
||
| 317 | |||
| 318 | !empty($account->getMailboxFormat()) ? $params['mailbox_format'] = $account->getMailboxFormat() : null; |
||
| 319 | |||
| 320 | if (!empty($options['mxcheck'])) { |
||
| 321 | if (!in_array($options['mxcheck'], ['local', 'secondary', 'remote', 'auto'])) { |
||
| 322 | throw new ClientExceptions("options[mxcheck] parameters must be one of local, secondary, remote, auto"); |
||
| 323 | } |
||
| 324 | |||
| 325 | $params['mxcheck'] = $options['mxcheck']; |
||
| 326 | } |
||
| 327 | |||
| 328 | if ($account->getMaxEmailPerHour() === -1) { |
||
| 329 | $params['max_email_per_hour'] = "unlimited"; |
||
| 330 | } elseif ($account->getMaxEmailPerHour() > 0) { |
||
| 331 | $params['max_email_per_hour'] = intval($account->getMaxEmailPerHour()); |
||
| 332 | } |
||
| 333 | |||
| 334 | if ($account->getMaxEmailAccountQuota() === -1) { |
||
| 335 | $params['max_emailacct_quota'] = "unlimited"; |
||
| 336 | } elseif ($account->getMaxEmailAccountQuota() > 0) { |
||
| 337 | $params['max_email_per_hour'] = intval($account->getMaxEmailAccountQuota()); |
||
| 338 | } |
||
| 339 | |||
| 340 | if ($account->getMaxDeferFailMailPercentage() === -1) { |
||
| 341 | $params['max_defer_fail_percentage'] = "unlimited"; |
||
| 342 | } elseif ($account->getMaxDeferFailMailPercentage() > 0) { |
||
| 343 | $params['max_defer_fail_percentage'] = intval($account->getMaxDeferFailMailPercentage()); |
||
| 344 | } |
||
| 345 | |||
| 346 | !empty($account->getUid()) ? $params['uid'] = $account->getUid() : null; |
||
| 347 | !empty($account->getPartition()) ? $params['homedir'] = $account->getPartition() : null; |
||
| 348 | !empty($options['dkim']) ? $params['dkim'] = intval($options['dkim']) : null; |
||
| 349 | !empty($options['spf']) ? $params['spf'] = intval($options['spf']) : null; |
||
| 350 | !empty($account->getOwner()) ? $params['owner'] = $account->getOwner() : null; |
||
| 351 | |||
| 352 | $result = $this->client->sendRequest("/json-api/createacct", "GET", $params); |
||
| 353 | |||
| 354 | if (!empty($result) && !empty($result['result'][0]) && $result['result'][0]['status'] === 0) { |
||
| 355 | throw new ClientExceptions($result['result'][0]['statusmsg']); |
||
| 356 | } |
||
| 357 | |||
| 358 | if (!empty($result) && !empty($result['result'][0]) && $result['result'][0]['status'] === 1) { |
||
| 359 | return ['result' => $result['result'][0]['options'], 'raw_output' => $result['result'][0]['rawout']]; |
||
| 360 | } |
||
| 361 | |||
| 362 | return []; |
||
| 363 | } |
||
| 365 |