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