| Conditions | 11 |
| Paths | 23 |
| Total Lines | 52 |
| Code Lines | 39 |
| 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 |
||
| 140 | protected function askOptions() |
||
| 141 | { |
||
| 142 | $values = []; |
||
| 143 | $request = $this->getRequest(); |
||
| 144 | echo '<form action="" method="post"><fieldset>'; |
||
| 145 | foreach ($this->options as $opt) { |
||
| 146 | $val = $request->requestVar($opt['key']); |
||
| 147 | if ($val === null) { |
||
| 148 | $val = $opt['default']; |
||
| 149 | } |
||
| 150 | |||
| 151 | $values[$opt['key']] = $val; |
||
| 152 | |||
| 153 | if ($opt['list']) { |
||
| 154 | $input = '<select name="' . $opt['key'] . '">'; |
||
| 155 | $input .= '<option></option>'; |
||
| 156 | foreach ($opt['list'] as $k => $v) { |
||
| 157 | $selected = ''; |
||
| 158 | if ($k == $val) { |
||
| 159 | $selected = ' selected="selected"'; |
||
| 160 | } |
||
| 161 | $input .= '<option value="' . $k . '"' . $selected . '>' . $v . '</option>'; |
||
| 162 | } |
||
| 163 | $input .= '</select>'; |
||
| 164 | } else { |
||
| 165 | $type = 'text'; |
||
| 166 | $input = null; |
||
| 167 | if (isset($opt['default'])) { |
||
| 168 | if (is_bool($opt['default'])) { |
||
| 169 | $type = 'checkbox'; |
||
| 170 | $checked = $val ? ' checked="checked"' : ''; |
||
| 171 | $input = '<input type="hidden" name="' . $opt['key'] . '" value="0" />'; |
||
| 172 | $input .= '<input type="' . $type . '" name="' . $opt['key'] . '" value="1"' . $checked . ' />'; |
||
| 173 | } else { |
||
| 174 | if (is_int($opt['default'])) { |
||
| 175 | $type = 'numeric'; |
||
| 176 | } |
||
| 177 | } |
||
| 178 | } |
||
| 179 | if (!$input) { |
||
| 180 | $input = '<input type="' . $type . '" name="' . $opt['key'] . '" value="' . $val . '" />'; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | echo '<div class="field">'; |
||
| 184 | echo '<label> ' . $opt['title'] . ' ' . $input . '</label>'; |
||
| 185 | echo '</div>'; |
||
| 186 | echo '<br/>'; |
||
| 187 | } |
||
| 188 | echo '</fieldset><br/><input type="submit" />'; |
||
| 189 | echo '</form>'; |
||
| 190 | echo '<hr/ >'; |
||
| 191 | return $values; |
||
| 192 | } |
||
| 253 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.