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