| 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 |
||
| 219 | public function create(Account $account, array $options = []) |
||
| 220 | { |
||
| 221 | if (empty($account->getUser())) { |
||
| 222 | throw ClientExceptions::invalidArgument("You must provide an username to create new account"); |
||
| 223 | } |
||
| 224 | |||
| 225 | if (empty($account->getDomain())) { |
||
| 226 | throw ClientExceptions::invalidArgument("You must provide a domain to create new account"); |
||
| 227 | } |
||
| 228 | |||
| 229 | $params = []; |
||
| 230 | $params['username'] = $account->getUser(); |
||
| 231 | $params['domain'] = $account->getDomain(); |
||
| 232 | !empty($account->getPlanName()) ? $params['plan'] = $account->getPlanName() : null; |
||
| 233 | !empty($options['pkgname']) ? $params['pkgname'] = $options['pkgname'] : null; |
||
| 234 | if (!empty($options['savepkg'])) { |
||
| 235 | if (!in_array(intval($options['savepkg']), [0, 1])) { |
||
| 236 | throw new ClientExceptions("`savepkg` must be either 0 or 1"); |
||
| 237 | } |
||
| 238 | |||
| 239 | $params['savepkg'] = $options['savepkg']; |
||
| 240 | } |
||
| 241 | |||
| 242 | !empty($options['featurelist']) ? $params['featurelist'] = $options['featurelist'] : null; |
||
| 243 | if (!empty($account->getDiskLimit())) { |
||
| 244 | if ($account->getDiskLimit() === -1) { |
||
| 245 | $params['quota'] = 0; |
||
| 246 | } else { |
||
| 247 | $params['quota'] = intval($account->getDiskLimit()); |
||
| 248 | } |
||
| 249 | } |
||
| 250 | |||
| 251 | !empty($account->getPassword()) ? $params['password'] = $account->getPassword() : null; |
||
| 252 | !empty($account->getIpAddress()) ? $params['ip'] = $account->getIpAddress() : null; |
||
| 253 | !empty($account->isCgiEnable()) ? $params['cgi'] = (int)$account->isCgiEnable() : null; |
||
| 254 | !empty($account->isSpamAssassinEnable()) ? |
||
| 255 | $params['spamassassin'] = (int)$account->isSpamAssassinEnable() |
||
| 256 | : null; |
||
| 257 | !empty($account->isFrontPageEnable()) ? $params['frontpage'] = (int)$account->isFrontPageEnable() : null; |
||
| 258 | !empty($account->getShell()) ? $params['hasshell'] = 1 : null; |
||
| 259 | !empty($account->getEmail()) ? $params['contactemail'] = 1 : null; |
||
| 260 | !empty($account->getEmail()) ? $params['contactemail'] = 1 : null; |
||
| 261 | !empty($account->getTheme()) ? $params['cpmod'] = 1 : null; |
||
| 262 | |||
| 263 | if ($account->getMaxFTP() === -1) { |
||
| 264 | $params['maxftp'] = "unlimited"; |
||
| 265 | } elseif ($account->getMaxFTP() > 0) { |
||
| 266 | $params['maxftp'] = intval($account->getMaxFTP()); |
||
| 267 | } |
||
| 268 | |||
| 269 | if ($account->getMaxSQL() === -1) { |
||
| 270 | $params['maxsql'] = "unlimited"; |
||
| 271 | } elseif ($account->getMaxSQL() > 0) { |
||
| 272 | $params['maxsql'] = intval($account->getMaxSQL()); |
||
| 273 | } |
||
| 274 | |||
| 275 | if ($account->getMaxPOP() === -1) { |
||
| 276 | $params['maxpop'] = "unlimited"; |
||
| 277 | } elseif ($account->getMaxPOP() > 0) { |
||
| 278 | $params['maxpop'] = intval($account->getMaxPOP()); |
||
| 279 | } |
||
| 280 | |||
| 281 | if ($account->getMaxMailingList() === -1) { |
||
| 282 | $params['maxlst'] = "unlimited"; |
||
| 283 | } elseif ($account->getMaxMailingList() > 0) { |
||
| 284 | $params['maxlst'] = intval($account->getMaxMailingList()); |
||
| 285 | } |
||
| 286 | |||
| 287 | if ($account->getMaxSubDomain() === -1) { |
||
| 288 | $params['maxsub'] = "unlimited"; |
||
| 289 | } elseif ($account->getMaxSubDomain() > 0) { |
||
| 290 | $params['maxsub'] = intval($account->getMaxSubDomain()); |
||
| 291 | } |
||
| 292 | |||
| 293 | if ($account->getMaxParkedDomains() === -1) { |
||
| 294 | $params['maxpark'] = "unlimited"; |
||
| 295 | } elseif ($account->getMaxParkedDomains() > 0) { |
||
| 296 | $params['maxpark'] = intval($account->getMaxParkedDomains()); |
||
| 297 | } |
||
| 298 | |||
| 299 | if ($account->getMaxAddonDomains() === -1) { |
||
| 300 | $params['maxaddon'] = "unlimited"; |
||
| 301 | } elseif ($account->getMaxAddonDomains() > 0) { |
||
| 302 | $params['maxaddon'] = intval($account->getMaxAddonDomains()); |
||
| 303 | } |
||
| 304 | |||
| 305 | if ($account->getBandwidthLimit() === -1) { |
||
| 306 | $params['bwlimit'] = "unlimited"; |
||
| 307 | } elseif ($account->getBandwidthLimit() > 0) { |
||
| 308 | $params['bwlimit'] = intval($account->getBandwidthLimit()); |
||
| 309 | } |
||
| 310 | |||
| 311 | !empty($options['customip']) ? $params['customip'] = $options['customip'] : null; |
||
| 312 | |||
| 313 | !empty($account->getLanguagePreference()) ? $params['language'] = $account->getLanguagePreference() : null; |
||
| 314 | |||
| 315 | !empty($options['useregns']) ? $params['useregns'] = $options['useregns'] : null; |
||
| 316 | !empty($options['reseller']) ? $params['reseller'] = (int)$options['reseller'] : null; |
||
| 317 | !empty($options['forcedns']) ? $params['forcedns'] = (int)$options['forcedns'] : null; |
||
| 318 | |||
| 319 | !empty($account->getMailboxFormat()) ? $params['mailbox_format'] = $account->getMailboxFormat() : null; |
||
| 320 | |||
| 321 | if (!empty($options['mxcheck'])) { |
||
| 322 | if (!in_array($options['mxcheck'], ['local', 'secondary', 'remote', 'auto'])) { |
||
| 323 | throw new ClientExceptions("options[mxcheck] parameters must be one of local, secondary, remote, auto"); |
||
| 324 | } |
||
| 325 | |||
| 326 | $params['mxcheck'] = $options['mxcheck']; |
||
| 327 | } |
||
| 328 | |||
| 329 | if ($account->getMaxEmailPerHour() === -1) { |
||
| 330 | $params['max_email_per_hour'] = "unlimited"; |
||
| 331 | } elseif ($account->getMaxEmailPerHour() > 0) { |
||
| 332 | $params['max_email_per_hour'] = intval($account->getMaxEmailPerHour()); |
||
| 333 | } |
||
| 334 | |||
| 335 | if ($account->getMaxEmailAccountQuota() === -1) { |
||
| 336 | $params['max_emailacct_quota'] = "unlimited"; |
||
| 337 | } elseif ($account->getMaxEmailAccountQuota() > 0) { |
||
| 338 | $params['max_email_per_hour'] = intval($account->getMaxEmailAccountQuota()); |
||
| 339 | } |
||
| 340 | |||
| 341 | if ($account->getMaxDeferFailMailPercentage() === -1) { |
||
| 342 | $params['max_defer_fail_percentage'] = "unlimited"; |
||
| 343 | } elseif ($account->getMaxDeferFailMailPercentage() > 0) { |
||
| 344 | $params['max_defer_fail_percentage'] = intval($account->getMaxDeferFailMailPercentage()); |
||
| 345 | } |
||
| 346 | |||
| 347 | !empty($account->getUid()) ? $params['uid'] = $account->getUid() : null; |
||
| 348 | !empty($account->getPartition()) ? $params['homedir'] = $account->getPartition() : null; |
||
| 349 | !empty($options['dkim']) ? $params['dkim'] = intval($options['dkim']) : null; |
||
| 350 | !empty($options['spf']) ? $params['spf'] = intval($options['spf']) : null; |
||
| 351 | !empty($account->getOwner()) ? $params['owner'] = $account->getOwner() : null; |
||
| 352 | |||
| 353 | $result = $this->client->sendRequest("/json-api/createacct", "GET", $params); |
||
| 354 | |||
| 355 | if (!empty($result) && !empty($result['result'][0]) && $result['result'][0]['status'] === 0) { |
||
| 356 | throw new ClientExceptions($result['result'][0]['statusmsg']); |
||
| 357 | } |
||
| 358 | |||
| 359 | if (!empty($result) && !empty($result['result'][0]) && $result['result'][0]['status'] === 1) { |
||
| 360 | return ['result' => $result['result'][0]['options'], 'raw_output' => $result['result'][0]['rawout']]; |
||
| 361 | } |
||
| 362 | |||
| 363 | return []; |
||
| 364 | } |
||
| 417 |