Conditions | 6 |
Paths | 1600 |
Total Lines | 135 |
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 |
||
89 | public function html() { |
||
90 | $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here. |
||
91 | global $lang; |
||
92 | global $ID; |
||
93 | |||
94 | if (is_null($this->_config)) { $this->_config = new configuration($this->_file); } |
||
95 | $this->setupLocale(true); |
||
96 | |||
97 | print $this->locale_xhtml('intro'); |
||
98 | |||
99 | ptln('<div id="config__manager">'); |
||
100 | |||
101 | if ($this->_config->locked) |
||
102 | ptln('<div class="info">'.$this->getLang('locked').'</div>'); |
||
103 | elseif ($this->_error) |
||
104 | ptln('<div class="error">'.$this->getLang('error').'</div>'); |
||
105 | elseif ($this->_changed) |
||
106 | ptln('<div class="success">'.$this->getLang('updated').'</div>'); |
||
107 | |||
108 | // POST to script() instead of wl($ID) so config manager still works if |
||
109 | // rewrite config is broken. Add $ID as hidden field to remember |
||
110 | // current ID in most cases. |
||
111 | ptln('<form action="'.script().'" method="post">'); |
||
112 | ptln('<div class="no"><input type="hidden" name="id" value="'.$ID.'" /></div>'); |
||
113 | formSecurityToken(); |
||
114 | $this->_print_h1('dokuwiki_settings', $this->getLang('_header_dokuwiki')); |
||
115 | |||
116 | /** @var setting[] $undefined_settings */ |
||
117 | $undefined_settings = array(); |
||
118 | $in_fieldset = false; |
||
119 | $first_plugin_fieldset = true; |
||
120 | $first_template_fieldset = true; |
||
121 | foreach($this->_config->setting as $setting) { |
||
122 | if (is_a($setting, 'setting_hidden')) { |
||
123 | // skip hidden (and undefined) settings |
||
124 | if ($allow_debug && is_a($setting, 'setting_undefined')) { |
||
125 | $undefined_settings[] = $setting; |
||
126 | } else { |
||
127 | continue; |
||
128 | } |
||
129 | } else if (is_a($setting, 'setting_fieldset')) { |
||
130 | // config setting group |
||
131 | if ($in_fieldset) { |
||
132 | ptln(' </table>'); |
||
133 | ptln(' </div>'); |
||
134 | ptln(' </fieldset>'); |
||
135 | } else { |
||
136 | $in_fieldset = true; |
||
137 | } |
||
138 | if ($first_plugin_fieldset && substr($setting->_key, 0, 10)=='plugin'.CM_KEYMARKER) { |
||
139 | $this->_print_h1('plugin_settings', $this->getLang('_header_plugin')); |
||
140 | $first_plugin_fieldset = false; |
||
141 | } else if ($first_template_fieldset && substr($setting->_key, 0, 7)=='tpl'.CM_KEYMARKER) { |
||
142 | $this->_print_h1('template_settings', $this->getLang('_header_template')); |
||
143 | $first_template_fieldset = false; |
||
144 | } |
||
145 | ptln(' <fieldset id="'.$setting->_key.'">'); |
||
146 | ptln(' <legend>'.$setting->prompt($this).'</legend>'); |
||
147 | ptln(' <div class="table">'); |
||
148 | ptln(' <table class="inline">'); |
||
149 | } else { |
||
150 | // config settings |
||
151 | list($label,$input) = $setting->html($this, $this->_error); |
||
152 | |||
153 | $class = $setting->is_default() ? ' class="default"' : ($setting->is_protected() ? ' class="protected"' : ''); |
||
154 | $error = $setting->error() ? ' class="value error"' : ' class="value"'; |
||
155 | $icon = $setting->caution() ? '<img src="'.DOKU_PLUGIN_IMAGES.$setting->caution().'.png" alt="'.$setting->caution().'" title="'.$this->getLang($setting->caution()).'" />' : ''; |
||
156 | |||
157 | ptln(' <tr'.$class.'>'); |
||
158 | ptln(' <td class="label">'); |
||
159 | ptln(' <span class="outkey">'.$setting->_out_key(true, true).'</span>'); |
||
160 | ptln(' '.$icon.$label); |
||
161 | ptln(' </td>'); |
||
162 | ptln(' <td'.$error.'>'.$input.'</td>'); |
||
163 | ptln(' </tr>'); |
||
164 | } |
||
165 | } |
||
166 | |||
167 | ptln(' </table>'); |
||
168 | ptln(' </div>'); |
||
169 | if ($in_fieldset) { |
||
170 | ptln(' </fieldset>'); |
||
171 | } |
||
172 | |||
173 | // show undefined settings list |
||
174 | if ($allow_debug && !empty($undefined_settings)) { |
||
175 | /** |
||
176 | * Callback for sorting settings |
||
177 | * |
||
178 | * @param setting $a |
||
179 | * @param setting $b |
||
180 | * @return int if $a is lower/equal/higher than $b |
||
181 | */ |
||
182 | function _setting_natural_comparison($a, $b) { |
||
|
|||
183 | return strnatcmp($a->_key, $b->_key); |
||
184 | } |
||
185 | |||
186 | usort($undefined_settings, '_setting_natural_comparison'); |
||
187 | $this->_print_h1('undefined_settings', $this->getLang('_header_undefined')); |
||
188 | ptln('<fieldset>'); |
||
189 | ptln('<div class="table">'); |
||
190 | ptln('<table class="inline">'); |
||
191 | $undefined_setting_match = array(); |
||
192 | foreach($undefined_settings as $setting) { |
||
193 | if (preg_match('/^(?:plugin|tpl)'.CM_KEYMARKER.'.*?'.CM_KEYMARKER.'(.*)$/', $setting->_key, $undefined_setting_match)) { |
||
194 | $undefined_setting_key = $undefined_setting_match[1]; |
||
195 | } else { |
||
196 | $undefined_setting_key = $setting->_key; |
||
197 | } |
||
198 | ptln(' <tr>'); |
||
199 | ptln(' <td class="label"><span title="$meta[\''.$undefined_setting_key.'\']">$'.$this->_config->_name.'[\''.$setting->_out_key().'\']</span></td>'); |
||
200 | ptln(' <td>'.$this->getLang('_msg_'.get_class($setting)).'</td>'); |
||
201 | ptln(' </tr>'); |
||
202 | } |
||
203 | ptln('</table>'); |
||
204 | ptln('</div>'); |
||
205 | ptln('</fieldset>'); |
||
206 | } |
||
207 | |||
208 | // finish up form |
||
209 | ptln('<p>'); |
||
210 | ptln(' <input type="hidden" name="do" value="admin" />'); |
||
211 | ptln(' <input type="hidden" name="page" value="config" />'); |
||
212 | |||
213 | if (!$this->_config->locked) { |
||
214 | ptln(' <input type="hidden" name="save" value="1" />'); |
||
215 | ptln(' <button type="submit" name="submit" accesskey="s">'.$lang['btn_save'].'</button>'); |
||
216 | ptln(' <button type="reset">'.$lang['btn_reset'].'</button>'); |
||
217 | } |
||
218 | |||
219 | ptln('</p>'); |
||
220 | |||
221 | ptln('</form>'); |
||
222 | ptln('</div>'); |
||
223 | } |
||
224 | |||
405 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.