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