Conditions | 10 |
Paths | 33 |
Total Lines | 73 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
46 | protected function create() |
||
47 | { |
||
48 | if (WebRequest::wasPosted()) { |
||
49 | $this->validateCSRFToken(); |
||
50 | $database = $this->getDatabase(); |
||
51 | |||
52 | $queue = new RequestQueue(); |
||
53 | |||
54 | $queue->setDatabase($database); |
||
55 | $queue->setDomain(1); // FIXME: domain |
||
56 | |||
57 | $queue->setHeader(WebRequest::postString('header')); |
||
|
|||
58 | $queue->setDisplayName(WebRequest::postString('displayName')); |
||
59 | $queue->setApiName(WebRequest::postString('apiName')); |
||
60 | $queue->setEnabled(WebRequest::postBoolean('enabled')); |
||
61 | $queue->setDefault(WebRequest::postBoolean('default') && WebRequest::postBoolean('enabled')); |
||
62 | $queue->setDefaultAntispoof(WebRequest::postBoolean('antispoof') && WebRequest::postBoolean('enabled')); |
||
63 | $queue->setDefaultTitleBlacklist(WebRequest::postBoolean('titleblacklist') && WebRequest::postBoolean('enabled')); |
||
64 | $queue->setHelp(WebRequest::postString('help')); |
||
65 | $queue->setLogName(WebRequest::postString('logName')); |
||
66 | |||
67 | $proceed = true; |
||
68 | |||
69 | if (RequestQueue::getByApiName($database, $queue->getApiName(), 1) !== false) { |
||
70 | // FIXME: domain |
||
71 | SessionAlert::error("The chosen API name is already in use. Please choose another."); |
||
72 | $proceed = false; |
||
73 | } |
||
74 | |||
75 | if (preg_match('/^[A-Za-z][a-zA-Z0-9_-]*$/', $queue->getApiName()) !== 1) { |
||
76 | SessionAlert::error("The chosen API name contains invalid characters"); |
||
77 | $proceed = false; |
||
78 | } |
||
79 | |||
80 | if (RequestQueue::getByDisplayName($database, $queue->getDisplayName(), 1) !== false) { |
||
81 | // FIXME: domain |
||
82 | SessionAlert::error("The chosen target display name is already in use. Please choose another."); |
||
83 | $proceed = false; |
||
84 | } |
||
85 | |||
86 | if (RequestQueue::getByHeader($database, $queue->getHeader(), 1) !== false) { |
||
87 | // FIXME: domain |
||
88 | SessionAlert::error("The chosen header is already in use. Please choose another."); |
||
89 | $proceed = false; |
||
90 | } |
||
91 | |||
92 | if ($proceed) { |
||
93 | $queue->save(); |
||
94 | Logger::requestQueueCreated($database, $queue); |
||
95 | $this->redirect('queueManagement'); |
||
96 | } |
||
97 | else { |
||
98 | $this->populateFromObject($queue); |
||
99 | |||
100 | $this->assign('createMode', true); |
||
101 | $this->setTemplate('queue-management/edit.tpl'); |
||
102 | } |
||
103 | } |
||
104 | else { |
||
105 | $this->assign('header', null); |
||
106 | $this->assign('displayName', null); |
||
107 | $this->assign('apiName', null); |
||
108 | $this->assign('enabled', false); |
||
109 | $this->assign('antispoof', false); |
||
110 | $this->assign('isTarget', false); |
||
111 | $this->assign('titleblacklist', false); |
||
112 | $this->assign('default', false); |
||
113 | $this->assign('help', null); |
||
114 | $this->assign('logName', null); |
||
115 | |||
116 | $this->assignCSRFToken(); |
||
117 | $this->assign('createMode', true); |
||
118 | $this->setTemplate('queue-management/edit.tpl'); |
||
119 | } |
||
209 | } |