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