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