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