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