| Conditions | 3 |
| Paths | 3 |
| Total Lines | 52 |
| Code Lines | 36 |
| 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 |
||
| 52 | protected function create() |
||
| 53 | { |
||
| 54 | $this->setHtmlTitle('Domain Management'); |
||
| 55 | $database = $this->getDatabase(); |
||
| 56 | $currentUser = User::getCurrent($database); |
||
| 57 | |||
| 58 | // quickly check the user is allowed to edit all fields. If not, then they shouldn't be allowed to create |
||
| 59 | // new domains either. With any luck, a competent developer would never grant create without editAll to a role |
||
| 60 | // anyway, so this will never be hit. |
||
| 61 | if (!$this->barrierTest('editAll', $currentUser)) { |
||
| 62 | throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
||
| 63 | } |
||
| 64 | |||
| 65 | if (WebRequest::wasPosted()) { |
||
| 66 | $this->validateCSRFToken(); |
||
| 67 | |||
| 68 | $domain = new Domain(); |
||
| 69 | $domain->setDatabase($database); |
||
| 70 | |||
| 71 | $domain->setShortName(WebRequest::postString('shortName')); |
||
|
|
|||
| 72 | $domain->setLongName(WebRequest::postString('longName')); |
||
| 73 | $domain->setWikiArticlePath(WebRequest::postString('articlePath')); |
||
| 74 | $domain->setWikiApiPath(WebRequest::postString('apiPath')); |
||
| 75 | $domain->setEnabled(WebRequest::postBoolean('enabled')); |
||
| 76 | $domain->setDefaultLanguage(WebRequest::postString('defaultLanguage')); |
||
| 77 | $domain->setDefaultClose(null); |
||
| 78 | $domain->setEmailReplyAddress(WebRequest::postString('emailReplyTo')); |
||
| 79 | $domain->setNotificationTarget(WebRequest::postString('notificationTarget')); |
||
| 80 | $domain->setLocalDocumentation(WebRequest::postString('localDocumentation')); |
||
| 81 | |||
| 82 | $domain->save(); |
||
| 83 | |||
| 84 | Logger::domainCreated($database, $domain); |
||
| 85 | $this->redirect('domainManagement'); |
||
| 86 | } |
||
| 87 | else { |
||
| 88 | $this->assignCSRFToken(); |
||
| 89 | |||
| 90 | $this->assign('shortName', ''); |
||
| 91 | $this->assign('longName', ''); |
||
| 92 | $this->assign('articlePath', ''); |
||
| 93 | $this->assign('apiPath', ''); |
||
| 94 | $this->assign('enabled', false); |
||
| 95 | $this->assign('defaultLanguage', 'en'); |
||
| 96 | $this->assign('emailReplyTo', ''); |
||
| 97 | $this->assign('notificationTarget', ''); |
||
| 98 | $this->assign('localDocumentation', ''); |
||
| 99 | |||
| 100 | $this->assign('createMode', true); |
||
| 101 | $this->assign('canEditAll', true); |
||
| 102 | |||
| 103 | $this->setTemplate('domain-management/edit.tpl'); |
||
| 104 | } |
||
| 174 |