| Conditions | 6 |
| Paths | 5 |
| Total Lines | 64 |
| Code Lines | 43 |
| 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 |
||
| 107 | protected function edit() |
||
| 108 | { |
||
| 109 | $this->setHtmlTitle('Domain Management'); |
||
| 110 | $database = $this->getDatabase(); |
||
| 111 | $currentUser = User::getCurrent($database); |
||
| 112 | |||
| 113 | $canEditAll = $this->barrierTest('editAll', $currentUser); |
||
| 114 | |||
| 115 | /** @var Domain $domain */ |
||
| 116 | $domain = Domain::getById(WebRequest::getInt('domain'), $database); |
||
| 117 | |||
| 118 | if (WebRequest::wasPosted()) { |
||
| 119 | $this->validateCSRFToken(); |
||
| 120 | |||
| 121 | $domain->setLongName(WebRequest::postString('longName')); |
||
| 122 | $domain->setDefaultLanguage(WebRequest::postString('defaultLanguage')); |
||
| 123 | $domain->setLocalDocumentation(WebRequest::postString('localDocumentation')); |
||
| 124 | |||
| 125 | /** @var EmailTemplate $template */ |
||
| 126 | $template = EmailTemplate::getById(WebRequest::postInt('defaultClose'), $database); |
||
| 127 | if ($template->getActive() |
||
| 128 | && $template->getPreloadOnly() === false |
||
| 129 | && $template->getDefaultAction() === EmailTemplate::ACTION_CREATED) { |
||
| 130 | $domain->setDefaultClose(WebRequest::postInt('defaultClose')); |
||
| 131 | } |
||
| 132 | else { |
||
| 133 | SessionAlert::warning("Chosen email template is not valid for use as the default creation template"); |
||
| 134 | } |
||
| 135 | |||
| 136 | if ($canEditAll) { |
||
| 137 | $domain->setWikiArticlePath(WebRequest::postString('articlePath')); |
||
| 138 | $domain->setWikiApiPath(WebRequest::postString('apiPath')); |
||
| 139 | $domain->setEnabled(WebRequest::postBoolean('enabled')); |
||
| 140 | $domain->setEmailReplyAddress(WebRequest::postString('emailReplyTo')); |
||
| 141 | $domain->setNotificationTarget(WebRequest::postString('notificationTarget')); |
||
| 142 | } |
||
| 143 | |||
| 144 | $domain->save(); |
||
| 145 | |||
| 146 | Logger::domainEdited($database, $domain); |
||
| 147 | $this->redirect('domainManagement'); |
||
| 148 | } |
||
| 149 | else { |
||
| 150 | $this->assignCSRFToken(); |
||
| 151 | |||
| 152 | $templates = EmailTemplate::getActiveNonpreloadTemplates(EmailTemplate::ACTION_CREATED, $database); |
||
| 153 | $this->assign('closeTemplates', $templates); |
||
| 154 | |||
| 155 | $this->assign('shortName', $domain->getShortName()); |
||
| 156 | $this->assign('longName', $domain->getLongName()); |
||
| 157 | $this->assign('articlePath', $domain->getWikiArticlePath()); |
||
| 158 | $this->assign('apiPath', $domain->getWikiApiPath()); |
||
| 159 | $this->assign('enabled', $domain->isEnabled()); |
||
| 160 | $this->assign('defaultClose', $domain->getDefaultClose()); |
||
| 161 | $this->assign('defaultLanguage', $domain->getDefaultLanguage()); |
||
| 162 | $this->assign('emailReplyTo', $domain->getEmailReplyAddress()); |
||
| 163 | $this->assign('notificationTarget', $domain->getNotificationTarget()); |
||
| 164 | $this->assign('localDocumentation', $domain->getLocalDocumentation()); |
||
| 165 | |||
| 166 | |||
| 167 | $this->assign('createMode', false); |
||
| 168 | $this->assign('canEditAll', $canEditAll); |
||
| 169 | |||
| 170 | $this->setTemplate('domain-management/edit.tpl'); |
||
| 171 | } |
||
| 174 |