| Conditions | 8 |
| Paths | 9 |
| Total Lines | 55 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 121 | protected function edit() |
||
| 122 | { |
||
| 123 | $database = $this->getDatabase(); |
||
| 124 | |||
| 125 | /** @var RequestQueue $queue */ |
||
| 126 | $queue = RequestQueue::getById(WebRequest::getInt('queue'), $database); |
||
| 127 | |||
| 128 | if (WebRequest::wasPosted()) { |
||
| 129 | $this->validateCSRFToken(); |
||
| 130 | |||
| 131 | $this->helper->configureDefaults( |
||
| 132 | $queue, |
||
| 133 | WebRequest::postBoolean('enabled'), |
||
| 134 | WebRequest::postBoolean('default'), |
||
| 135 | WebRequest::postBoolean('antispoof'), |
||
| 136 | WebRequest::postBoolean('titleblacklist'), |
||
| 137 | $this->helper->isEmailTemplateTarget($queue, $this->getDatabase()) || $this->helper->isRequestFormTarget($queue, $this->getDatabase())); |
||
| 138 | |||
| 139 | $queue->setHeader(WebRequest::postString('header')); |
||
| 140 | $queue->setDisplayName(WebRequest::postString('displayName')); |
||
| 141 | $queue->setHelp(WebRequest::postString('help')); |
||
| 142 | |||
| 143 | $proceed = true; |
||
| 144 | |||
| 145 | $foundRequestQueue = RequestQueue::getByDisplayName($database, $queue->getDisplayName(), 1); |
||
| 146 | if ($foundRequestQueue !== false && $foundRequestQueue->getId() !== $queue->getId()) { |
||
| 147 | // FIXME: domain |
||
| 148 | SessionAlert::error("The chosen target display name is already in use. Please choose another."); |
||
| 149 | $proceed = false; |
||
| 150 | } |
||
| 151 | |||
| 152 | $foundRequestQueue = RequestQueue::getByHeader($database, $queue->getHeader(), 1); |
||
| 153 | if ($foundRequestQueue !== false && $foundRequestQueue->getId() !== $queue->getId()) { |
||
| 154 | // FIXME: domain |
||
| 155 | SessionAlert::error("The chosen header is already in use. Please choose another."); |
||
| 156 | $proceed = false; |
||
| 157 | } |
||
| 158 | |||
| 159 | if ($proceed) { |
||
| 160 | Logger::requestQueueEdited($database, $queue); |
||
| 161 | $queue->save(); |
||
| 162 | $this->redirect('queueManagement'); |
||
| 163 | } |
||
| 164 | else { |
||
| 165 | $this->populateFromObject($queue); |
||
| 166 | |||
| 167 | $this->assign('createMode', false); |
||
| 168 | $this->setTemplate('queue-management/edit.tpl'); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | else { |
||
| 172 | $this->populateFromObject($queue); |
||
| 173 | |||
| 174 | $this->assign('createMode', false); |
||
| 175 | $this->setTemplate('queue-management/edit.tpl'); |
||
| 176 | } |
||
| 201 | } |