| Conditions | 10 |
| Paths | 33 |
| Total Lines | 73 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 45 | protected function create() |
||
| 46 | { |
||
| 47 | if (WebRequest::wasPosted()) { |
||
| 48 | $this->validateCSRFToken(); |
||
| 49 | $database = $this->getDatabase(); |
||
| 50 | |||
| 51 | $queue = new RequestQueue(); |
||
| 52 | |||
| 53 | $queue->setDatabase($database); |
||
| 54 | $queue->setDomain(1); // FIXME: domain |
||
| 55 | |||
| 56 | $queue->setHeader(WebRequest::postString('header')); |
||
|
|
|||
| 57 | $queue->setDisplayName(WebRequest::postString('displayName')); |
||
| 58 | $queue->setApiName(WebRequest::postString('apiName')); |
||
| 59 | $queue->setEnabled(WebRequest::postBoolean('enabled')); |
||
| 60 | $queue->setDefault(WebRequest::postBoolean('default') && WebRequest::postBoolean('enabled')); |
||
| 61 | $queue->setDefaultAntispoof(WebRequest::postBoolean('antispoof') && WebRequest::postBoolean('enabled')); |
||
| 62 | $queue->setDefaultTitleBlacklist(WebRequest::postBoolean('titleblacklist') && WebRequest::postBoolean('enabled')); |
||
| 63 | $queue->setHelp(WebRequest::postString('help')); |
||
| 64 | $queue->setLogName(WebRequest::postString('logName')); |
||
| 65 | |||
| 66 | $proceed = true; |
||
| 67 | |||
| 68 | if (RequestQueue::getByApiName($database, $queue->getApiName(), 1) !== false) { |
||
| 69 | // FIXME: domain |
||
| 70 | SessionAlert::error("The chosen API name is already in use. Please choose another."); |
||
| 71 | $proceed = false; |
||
| 72 | } |
||
| 73 | |||
| 74 | if (preg_match('/^[A-Za-z][a-zA-Z0-9_-]*$/', $queue->getApiName()) !== 1) { |
||
| 75 | SessionAlert::error("The chosen API name contains invalid characters"); |
||
| 76 | $proceed = false; |
||
| 77 | } |
||
| 78 | |||
| 79 | if (RequestQueue::getByDisplayName($database, $queue->getDisplayName(), 1) !== false) { |
||
| 80 | // FIXME: domain |
||
| 81 | SessionAlert::error("The chosen target display name is already in use. Please choose another."); |
||
| 82 | $proceed = false; |
||
| 83 | } |
||
| 84 | |||
| 85 | if (RequestQueue::getByHeader($database, $queue->getHeader(), 1) !== false) { |
||
| 86 | // FIXME: domain |
||
| 87 | SessionAlert::error("The chosen header is already in use. Please choose another."); |
||
| 88 | $proceed = false; |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($proceed) { |
||
| 92 | $queue->save(); |
||
| 93 | Logger::requestQueueCreated($database, $queue); |
||
| 94 | $this->redirect('queueManagement'); |
||
| 95 | } |
||
| 96 | else { |
||
| 97 | $this->populateFromObject($queue); |
||
| 98 | |||
| 99 | $this->assign('createMode', true); |
||
| 100 | $this->setTemplate('queue-management/edit.tpl'); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | else { |
||
| 104 | $this->assign('header', null); |
||
| 105 | $this->assign('displayName', null); |
||
| 106 | $this->assign('apiName', null); |
||
| 107 | $this->assign('enabled', false); |
||
| 108 | $this->assign('antispoof', false); |
||
| 109 | $this->assign('isTarget', false); |
||
| 110 | $this->assign('titleblacklist', false); |
||
| 111 | $this->assign('default', false); |
||
| 112 | $this->assign('help', null); |
||
| 113 | $this->assign('logName', null); |
||
| 114 | |||
| 115 | $this->assignCSRFToken(); |
||
| 116 | $this->assign('createMode', true); |
||
| 117 | $this->setTemplate('queue-management/edit.tpl'); |
||
| 118 | } |
||
| 201 | } |