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