| Conditions | 16 | 
| Paths | 792 | 
| Total Lines | 71 | 
| 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  | 
            ||
| 36 |     public function html(\admin_plugin_config $plugin, $echo = false) { | 
            ||
| 37 | |||
| 38 | $disable = '';  | 
            ||
| 39 | |||
| 40 |         if($this->isProtected()) { | 
            ||
| 41 | $value = $this->protected;  | 
            ||
| 42 | $disable = 'disabled="disabled"';  | 
            ||
| 43 |         } else { | 
            ||
| 44 |             if($echo && $this->error) { | 
            ||
| 45 | $value = $this->input;  | 
            ||
| 46 |             } else { | 
            ||
| 47 | $value = is_null($this->local) ? $this->default : $this->local;  | 
            ||
| 48 | }  | 
            ||
| 49 | }  | 
            ||
| 50 | |||
| 51 | $key = htmlspecialchars($this->key);  | 
            ||
| 52 | |||
| 53 | // convert from comma separated list into array + combine complimentary actions  | 
            ||
| 54 | $value = $this->str2array($value);  | 
            ||
| 55 | $default = $this->str2array($this->default);  | 
            ||
| 56 | |||
| 57 | $input = '';  | 
            ||
| 58 |         foreach($this->choices as $choice) { | 
            ||
| 59 | $idx = array_search($choice, $value);  | 
            ||
| 60 | $idx_default = array_search($choice, $default);  | 
            ||
| 61 | |||
| 62 | $checked = ($idx !== false) ? 'checked="checked"' : '';  | 
            ||
| 63 | |||
| 64 | // @todo ideally this would be handled using a second class of "default"  | 
            ||
| 65 | $class = (($idx !== false) == (false !== $idx_default)) ? " selectiondefault" : "";  | 
            ||
| 66 | |||
| 67 | $prompt = ($plugin->getLang($this->key . '_' . $choice) ?  | 
            ||
| 68 | $plugin->getLang($this->key . '_' . $choice) : htmlspecialchars($choice));  | 
            ||
| 69 | |||
| 70 | $input .= '<div class="selection' . $class . '">' . "\n";  | 
            ||
| 71 | $input .= '<label for="config___' . $key . '_' . $choice . '">' . $prompt . "</label>\n";  | 
            ||
| 72 | $input .= '<input id="config___' . $key . '_' . $choice . '" name="config[' . $key .  | 
            ||
| 73 | '][]" type="checkbox" class="checkbox" value="' . $choice . '" ' . $disable . ' ' . $checked . "/>\n";  | 
            ||
| 74 | $input .= "</div>\n";  | 
            ||
| 75 | |||
| 76 | // remove this action from the disabledactions array  | 
            ||
| 77 | if($idx !== false) unset($value[$idx]);  | 
            ||
| 78 | if($idx_default !== false) unset($default[$idx_default]);  | 
            ||
| 79 | }  | 
            ||
| 80 | |||
| 81 | // handle any remaining values  | 
            ||
| 82 |         if($this->other != 'never') { | 
            ||
| 83 |             $other = join(',', $value); | 
            ||
| 84 | // test equivalent to ($this->_other == 'always' || ($other && $this->_other == 'exists')  | 
            ||
| 85 | // use != 'exists' rather than == 'always' to ensure invalid values default to 'always'  | 
            ||
| 86 |             if($this->other != 'exists' || $other) { | 
            ||
| 87 | |||
| 88 | $class = (  | 
            ||
| 89 | (count($default) == count($value)) &&  | 
            ||
| 90 | (count($value) == count(array_intersect($value, $default)))  | 
            ||
| 91 | ) ?  | 
            ||
| 92 | " selectiondefault" : "";  | 
            ||
| 93 | |||
| 94 | $input .= '<div class="other' . $class . '">' . "\n";  | 
            ||
| 95 | $input .= '<label for="config___' . $key . '_other">' .  | 
            ||
| 96 | $plugin->getLang($key . '_other') .  | 
            ||
| 97 | "</label>\n";  | 
            ||
| 98 | $input .= '<input id="config___' . $key . '_other" name="config[' . $key .  | 
            ||
| 99 | '][other]" type="text" class="edit" value="' . htmlspecialchars($other) .  | 
            ||
| 100 | '" ' . $disable . " />\n";  | 
            ||
| 101 | $input .= "</div>\n";  | 
            ||
| 102 | }  | 
            ||
| 103 | }  | 
            ||
| 104 | $label = '<label>' . $this->prompt($plugin) . '</label>';  | 
            ||
| 105 | return array($label, $input);  | 
            ||
| 106 | }  | 
            ||
| 107 | |||
| 164 |