Conditions | 11 |
Paths | 108 |
Total Lines | 44 |
Code Lines | 29 |
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 |
||
13 | public function html(\admin_plugin_config $plugin, $echo = false) { |
||
14 | $disable = ''; |
||
15 | $nochoice = ''; |
||
16 | |||
17 | if($this->isProtected()) { |
||
18 | $value = $this->protected; |
||
19 | $disable = ' disabled="disabled"'; |
||
20 | } else { |
||
21 | $value = is_null($this->local) ? $this->default : $this->local; |
||
22 | } |
||
23 | |||
24 | // ensure current value is included |
||
25 | if(!in_array($value, $this->choices)) { |
||
26 | $this->choices[] = $value; |
||
27 | } |
||
28 | // disable if no other choices |
||
29 | if(!$this->isProtected() && count($this->choices) <= 1) { |
||
30 | $disable = ' disabled="disabled"'; |
||
31 | $nochoice = $plugin->getLang('nochoice'); |
||
32 | } |
||
33 | |||
34 | $key = htmlspecialchars($this->key); |
||
35 | |||
36 | $label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>'; |
||
37 | |||
38 | $input = "<div class=\"input\">\n"; |
||
39 | $input .= '<select class="edit" id="config___' . $key . '" name="config[' . $key . ']"' . $disable . '>' . "\n"; |
||
40 | foreach($this->choices as $choice) { |
||
41 | $selected = ($value == $choice) ? ' selected="selected"' : ''; |
||
42 | $option = $plugin->getLang($this->key . '_o_' . $choice); |
||
43 | if(!$option && isset($this->lang[$this->key . '_o_' . $choice])) { |
||
44 | $option = $this->lang[$this->key . '_o_' . $choice]; |
||
45 | } |
||
46 | if(!$option) $option = $choice; |
||
47 | |||
48 | $choice = htmlspecialchars($choice); |
||
49 | $option = htmlspecialchars($option); |
||
50 | $input .= ' <option value="' . $choice . '"' . $selected . ' >' . $option . '</option>' . "\n"; |
||
51 | } |
||
52 | $input .= "</select> $nochoice \n"; |
||
53 | $input .= "</div>\n"; |
||
54 | |||
55 | return array($label, $input); |
||
56 | } |
||
57 | |||
72 |