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