| Conditions | 6 |
| Paths | 384 |
| Total Lines | 142 |
| Code Lines | 97 |
| 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 |
||
| 69 | public function html() { |
||
| 70 | $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here. |
||
| 71 | global $lang; |
||
| 72 | global $ID; |
||
| 73 | |||
| 74 | $this->setupLocale(true); |
||
| 75 | |||
| 76 | print $this->locale_xhtml('intro'); |
||
| 77 | |||
| 78 | ptln('<div id="config__manager">'); |
||
| 79 | |||
| 80 | if($this->configuration->isLocked()) { |
||
| 81 | ptln('<div class="info">' . $this->getLang('locked') . '</div>'); |
||
| 82 | } |
||
| 83 | |||
| 84 | // POST to script() instead of wl($ID) so config manager still works if |
||
| 85 | // rewrite config is broken. Add $ID as hidden field to remember |
||
| 86 | // current ID in most cases. |
||
| 87 | ptln('<form action="' . script() . '" method="post">'); |
||
| 88 | ptln('<div class="no"><input type="hidden" name="id" value="' . $ID . '" /></div>'); |
||
| 89 | formSecurityToken(); |
||
| 90 | $this->_print_h1('dokuwiki_settings', $this->getLang('_header_dokuwiki')); |
||
| 91 | |||
| 92 | $in_fieldset = false; |
||
| 93 | $first_plugin_fieldset = true; |
||
| 94 | $first_template_fieldset = true; |
||
| 95 | foreach($this->configuration->getSettings() as $setting) { |
||
| 96 | if(is_a($setting, SettingHidden::class)) { |
||
| 97 | continue; |
||
| 98 | } else if(is_a($setting, settingFieldset::class)) { |
||
| 99 | // config setting group |
||
| 100 | if($in_fieldset) { |
||
| 101 | ptln(' </table>'); |
||
| 102 | ptln(' </div>'); |
||
| 103 | ptln(' </fieldset>'); |
||
| 104 | } else { |
||
| 105 | $in_fieldset = true; |
||
| 106 | } |
||
| 107 | // fixme this should probably be a function in setting: |
||
| 108 | if($first_plugin_fieldset && substr($setting->getKey(), 0, 10) == 'plugin' . Configuration::KEYMARKER) { |
||
| 109 | $this->_print_h1('plugin_settings', $this->getLang('_header_plugin')); |
||
| 110 | $first_plugin_fieldset = false; |
||
| 111 | } else if($first_template_fieldset && substr($setting->getKey(), 0, 7) == 'tpl' . Configuration::KEYMARKER) { |
||
| 112 | $this->_print_h1('template_settings', $this->getLang('_header_template')); |
||
| 113 | $first_template_fieldset = false; |
||
| 114 | } |
||
| 115 | ptln(' <fieldset id="' . $setting->getKey() . '">'); |
||
| 116 | ptln(' <legend>' . $setting->prompt($this) . '</legend>'); |
||
| 117 | ptln(' <div class="table">'); |
||
| 118 | ptln(' <table class="inline">'); |
||
| 119 | } else { |
||
| 120 | // config settings |
||
| 121 | list($label, $input) = $setting->html($this, $this->_error); |
||
|
|
|||
| 122 | |||
| 123 | $class = $setting->is_default() |
||
| 124 | ? ' class="default"' |
||
| 125 | : ($setting->is_protected() ? ' class="protected"' : ''); |
||
| 126 | $error = $setting->error() |
||
| 127 | ? ' class="value error"' |
||
| 128 | : ' class="value"'; |
||
| 129 | $icon = $setting->caution() |
||
| 130 | ? '<img src="' . self::IMGDIR . $setting->caution() . '.png" ' . |
||
| 131 | 'alt="' . $setting->caution() . '" title="' . $this->getLang($setting->caution()) . '" />' |
||
| 132 | : ''; |
||
| 133 | |||
| 134 | ptln(' <tr' . $class . '>'); |
||
| 135 | ptln(' <td class="label">'); |
||
| 136 | ptln(' <span class="outkey">' . $setting->_out_key(true, true) . '</span>'); |
||
| 137 | ptln(' ' . $icon . $label); |
||
| 138 | ptln(' </td>'); |
||
| 139 | ptln(' <td' . $error . '>' . $input . '</td>'); |
||
| 140 | ptln(' </tr>'); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | ptln(' </table>'); |
||
| 145 | ptln(' </div>'); |
||
| 146 | if($in_fieldset) { |
||
| 147 | ptln(' </fieldset>'); |
||
| 148 | } |
||
| 149 | |||
| 150 | // show undefined settings list |
||
| 151 | $undefined_settings = $this->configuration->getUndefined(); |
||
| 152 | if($allow_debug && !empty($undefined_settings)) { |
||
| 153 | /** |
||
| 154 | * Callback for sorting settings |
||
| 155 | * |
||
| 156 | * @param Setting $a |
||
| 157 | * @param Setting $b |
||
| 158 | * @return int if $a is lower/equal/higher than $b |
||
| 159 | */ |
||
| 160 | function _setting_natural_comparison($a, $b) { |
||
| 161 | return strnatcmp($a->getKey(), $b->getKey()); |
||
| 162 | } |
||
| 163 | |||
| 164 | usort($undefined_settings, '_setting_natural_comparison'); |
||
| 165 | $this->_print_h1('undefined_settings', $this->getLang('_header_undefined')); |
||
| 166 | ptln('<fieldset>'); |
||
| 167 | ptln('<div class="table">'); |
||
| 168 | ptln('<table class="inline">'); |
||
| 169 | $undefined_setting_match = array(); |
||
| 170 | foreach($undefined_settings as $setting) { |
||
| 171 | if( |
||
| 172 | preg_match( |
||
| 173 | '/^(?:plugin|tpl)' . Configuration::KEYMARKER . '.*?' . Configuration::KEYMARKER . '(.*)$/', |
||
| 174 | $setting->getKey(), |
||
| 175 | $undefined_setting_match |
||
| 176 | ) |
||
| 177 | ) { |
||
| 178 | $undefined_setting_key = $undefined_setting_match[1]; |
||
| 179 | } else { |
||
| 180 | $undefined_setting_key = $setting->getKey(); |
||
| 181 | } |
||
| 182 | ptln(' <tr>'); |
||
| 183 | ptln( |
||
| 184 | ' <td class="label"><span title="$meta[\'' . $undefined_setting_key . '\']">$' . |
||
| 185 | 'conf' . '[\'' . $setting->_out_key() . '\']</span></td>' |
||
| 186 | ); |
||
| 187 | ptln(' <td>' . $this->getLang('_msg_' . get_class($setting)) . '</td>'); |
||
| 188 | ptln(' </tr>'); |
||
| 189 | } |
||
| 190 | ptln('</table>'); |
||
| 191 | ptln('</div>'); |
||
| 192 | ptln('</fieldset>'); |
||
| 193 | } |
||
| 194 | |||
| 195 | // finish up form |
||
| 196 | ptln('<p>'); |
||
| 197 | ptln(' <input type="hidden" name="do" value="admin" />'); |
||
| 198 | ptln(' <input type="hidden" name="page" value="config" />'); |
||
| 199 | |||
| 200 | if(!$this->configuration->isLocked()) { |
||
| 201 | ptln(' <input type="hidden" name="save" value="1" />'); |
||
| 202 | ptln(' <button type="submit" name="submit" accesskey="s">' . $lang['btn_save'] . '</button>'); |
||
| 203 | ptln(' <button type="reset">' . $lang['btn_reset'] . '</button>'); |
||
| 204 | } |
||
| 205 | |||
| 206 | ptln('</p>'); |
||
| 207 | |||
| 208 | ptln('</form>'); |
||
| 209 | ptln('</div>'); |
||
| 210 | } |
||
| 211 | |||
| 300 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: