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