| Conditions | 9 |
| Paths | 5 |
| Total Lines | 104 |
| Code Lines | 88 |
| 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 \sprintf( |
||
| 176 | '<tr><th class="data left required">%s</th>', |
||
| 177 | $this->lang['strname'] |
||
| 178 | ) . \PHP_EOL; |
||
| 179 | echo \sprintf( |
||
| 180 | '<td class="data1"><input name="name" size="16" maxlength="%s" value="', |
||
| 181 | $data->_maxNameLen |
||
| 182 | ), |
||
| 183 | \htmlspecialchars($_POST['name']), '" /></td></tr>' . \PHP_EOL; |
||
| 184 | echo \sprintf( |
||
| 185 | '<tr><th class="data left required">%s</th>', |
||
| 186 | $this->lang['strevent'] |
||
| 187 | ) . \PHP_EOL; |
||
| 188 | echo '<td class="data1"><select name="event">' . \PHP_EOL; |
||
| 189 | |||
| 190 | foreach ($data->rule_events as $v) { |
||
| 191 | echo \sprintf( |
||
| 192 | '<option value="%s"', |
||
| 193 | $v |
||
| 194 | ), ($v === $_POST['event']) ? ' selected="selected"' : '', |
||
| 195 | \sprintf( |
||
| 196 | '>%s</option>', |
||
| 197 | $v |
||
| 198 | ) . \PHP_EOL; |
||
| 199 | } |
||
| 200 | echo '</select></td></tr>' . \PHP_EOL; |
||
| 201 | echo \sprintf( |
||
| 202 | '<tr><th class="data left">%s</th>', |
||
| 203 | $this->lang['strwhere'] |
||
| 204 | ) . \PHP_EOL; |
||
| 205 | echo '<td class="data1"><input name="where" size="32" value="', |
||
| 206 | \htmlspecialchars($_POST['where']), '" /></td></tr>' . \PHP_EOL; |
||
| 207 | echo \sprintf( |
||
| 208 | '<tr><th class="data left"><label for="instead">%s</label></th>', |
||
| 209 | $this->lang['strinstead'] |
||
| 210 | ) . \PHP_EOL; |
||
| 211 | echo '<td class="data1">'; |
||
| 212 | echo '<input type="checkbox" id="instead" name="instead" ', (isset($_POST['instead'])) ? ' checked="checked"' : '', ' />' . \PHP_EOL; |
||
| 213 | echo '</td></tr>' . \PHP_EOL; |
||
| 214 | echo \sprintf( |
||
| 215 | '<tr><th class="data left required">%s</th>', |
||
| 216 | $this->lang['straction'] |
||
| 217 | ) . \PHP_EOL; |
||
| 218 | echo '<td class="data1">'; |
||
| 219 | echo '<input type="radio" id="type1" name="type" value="NOTHING"', ('NOTHING' === $_POST['type']) ? ' checked="checked"' : '', ' /> <label for="type1">NOTHING</label><br />' . \PHP_EOL; |
||
| 220 | echo '<input type="radio" name="type" value="SOMETHING"', ('SOMETHING' === $_POST['type']) ? ' checked="checked"' : '', ' />' . \PHP_EOL; |
||
| 221 | echo '(<input name="raction" size="32" value="', |
||
| 222 | \htmlspecialchars($_POST['raction']), '" />)</td></tr>' . \PHP_EOL; |
||
| 223 | echo '</table>' . \PHP_EOL; |
||
| 224 | |||
| 225 | echo '<input type="hidden" name="action" value="save_create_rule" />' . \PHP_EOL; |
||
| 226 | echo '<input type="hidden" name="subject" value="', \htmlspecialchars($_REQUEST['subject']), '" />' . \PHP_EOL; |
||
| 227 | echo '<input type="hidden" name="', \htmlspecialchars($_REQUEST['subject']), |
||
| 228 | '" value="', \htmlspecialchars($_REQUEST[$_REQUEST['subject']]), '" />' . \PHP_EOL; |
||
| 229 | echo $this->view->form; |
||
| 230 | echo \sprintf( |
||
| 231 | '<p><input type="submit" name="ok" value="%s" />', |
||
| 232 | $this->lang['strcreate'] |
||
| 233 | ) . \PHP_EOL; |
||
| 234 | echo \sprintf( |
||
| 235 | '<input type="submit" name="cancel" value="%s" /></p>%s', |
||
| 236 | $this->lang['strcancel'], |
||
| 237 | \PHP_EOL |
||
| 238 | ); |
||
| 239 | echo '</form>' . \PHP_EOL; |
||
| 240 | } else { |
||
| 241 | if ('' === \trim($_POST['name'])) { |
||
| 242 | $this->createRule(true, $this->lang['strruleneedsname']); |
||
| 243 | } else { |
||
| 244 | $status = $data->createRule( |
||
| 245 | $_POST['name'], |
||
| 246 | $_POST['event'], |
||
| 247 | $_POST[$_POST['subject']], |
||
| 248 | $_POST['where'], |
||
| 249 | isset($_POST['instead']), |
||
| 250 | $_POST['type'], |
||
| 251 | $_POST['raction'] |
||
| 252 | ); |
||
| 253 | |||
| 254 | if (0 === $status) { |
||
| 255 | $this->doDefault($this->lang['strrulecreated']); |
||
| 256 | } else { |
||
| 257 | $this->createRule(true, $this->lang['strrulecreatedbad']); |
||
| 258 | } |
||
| 313 |