Conditions | 9 |
Paths | 5 |
Total Lines | 71 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
157 | public function createRule($confirm, $msg = '') |
||
158 | { |
||
159 | $data = $this->misc->getDatabaseAccessor(); |
||
160 | |||
161 | $this->coalesceArr($_POST, 'name', ''); |
||
162 | |||
163 | $this->coalesceArr($_POST, 'event', ''); |
||
164 | |||
165 | $this->coalesceArr($_POST, 'where', ''); |
||
166 | |||
167 | $this->coalesceArr($_POST, 'type', 'SOMETHING'); |
||
168 | |||
169 | $this->coalesceArr($_POST, 'raction', ''); |
||
170 | |||
171 | if ($confirm) { |
||
172 | $this->printTrail($_REQUEST['subject']); |
||
173 | $this->printTitle($this->lang['strcreaterule'], 'pg.rule.create'); |
||
174 | $this->printMsg($msg); |
||
175 | |||
176 | echo '<form action="' . \SUBFOLDER . "/src/views/rules\" method=\"post\">\n"; |
||
177 | echo "<table>\n"; |
||
178 | echo "<tr><th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
179 | echo "<td class=\"data1\"><input name=\"name\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
180 | htmlspecialchars($_POST['name']), "\" /></td></tr>\n"; |
||
181 | echo "<tr><th class=\"data left required\">{$this->lang['strevent']}</th>\n"; |
||
182 | echo "<td class=\"data1\"><select name=\"event\">\n"; |
||
183 | foreach ($data->rule_events as $v) { |
||
184 | echo "<option value=\"{$v}\"", ($v == $_POST['event']) ? ' selected="selected"' : '', |
||
185 | ">{$v}</option>\n"; |
||
186 | } |
||
187 | echo "</select></td></tr>\n"; |
||
188 | echo "<tr><th class=\"data left\">{$this->lang['strwhere']}</th>\n"; |
||
189 | echo '<td class="data1"><input name="where" size="32" value="', |
||
190 | htmlspecialchars($_POST['where']), "\" /></td></tr>\n"; |
||
191 | echo "<tr><th class=\"data left\"><label for=\"instead\">{$this->lang['strinstead']}</label></th>\n"; |
||
192 | echo '<td class="data1">'; |
||
193 | echo '<input type="checkbox" id="instead" name="instead" ', (isset($_POST['instead'])) ? ' checked="checked"' : '', " />\n"; |
||
194 | echo "</td></tr>\n"; |
||
195 | echo "<tr><th class=\"data left required\">{$this->lang['straction']}</th>\n"; |
||
196 | echo '<td class="data1">'; |
||
197 | echo '<input type="radio" id="type1" name="type" value="NOTHING"', ('NOTHING' == $_POST['type']) ? ' checked="checked"' : '', " /> <label for=\"type1\">NOTHING</label><br />\n"; |
||
198 | echo '<input type="radio" name="type" value="SOMETHING"', ('SOMETHING' == $_POST['type']) ? ' checked="checked"' : '', " />\n"; |
||
199 | echo '(<input name="raction" size="32" value="', |
||
200 | htmlspecialchars($_POST['raction']), "\" />)</td></tr>\n"; |
||
201 | echo "</table>\n"; |
||
202 | |||
203 | echo "<input type=\"hidden\" name=\"action\" value=\"save_create_rule\" />\n"; |
||
204 | echo '<input type="hidden" name="subject" value="', htmlspecialchars($_REQUEST['subject']), "\" />\n"; |
||
205 | echo '<input type="hidden" name="', htmlspecialchars($_REQUEST['subject']), |
||
206 | '" value="', htmlspecialchars($_REQUEST[$_REQUEST['subject']]), "\" />\n"; |
||
207 | echo $this->misc->form; |
||
208 | echo "<p><input type=\"submit\" name=\"ok\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
209 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
210 | echo "</form>\n"; |
||
211 | } else { |
||
212 | if ('' == trim($_POST['name'])) { |
||
213 | $this->createRule(true, $this->lang['strruleneedsname']); |
||
214 | } else { |
||
215 | $status = $data->createRule( |
||
216 | $_POST['name'], |
||
217 | $_POST['event'], |
||
218 | $_POST[$_POST['subject']], |
||
219 | $_POST['where'], |
||
220 | isset($_POST['instead']), |
||
221 | $_POST['type'], |
||
222 | $_POST['raction'] |
||
223 | ); |
||
224 | if (0 == $status) { |
||
225 | $this->doDefault($this->lang['strrulecreated']); |
||
226 | } else { |
||
227 | $this->createRule(true, $this->lang['strrulecreatedbad']); |
||
228 | } |
||
273 |