Conditions | 5 |
Paths | 384 |
Total Lines | 127 |
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 |
||
71 | public function html() { |
||
72 | $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here. |
||
73 | global $lang; |
||
74 | global $ID; |
||
75 | |||
76 | $this->setupLocale(true); |
||
77 | |||
78 | echo $this->locale_xhtml('intro'); |
||
79 | |||
80 | echo '<div id="config__manager">'; |
||
81 | |||
82 | if($this->configuration->isLocked()) { |
||
83 | echo '<div class="info">' . $this->getLang('locked') . '</div>'; |
||
84 | } |
||
85 | |||
86 | // POST to script() instead of wl($ID) so config manager still works if |
||
87 | // rewrite config is broken. Add $ID as hidden field to remember |
||
88 | // current ID in most cases. |
||
89 | echo '<form id="dw__configform" action="' . script() . '" method="post">'; |
||
90 | echo '<div class="no"><input type="hidden" name="id" value="' . $ID . '" /></div>'; |
||
91 | formSecurityToken(); |
||
92 | $this->printH1('dokuwiki_settings', $this->getLang('_header_dokuwiki')); |
||
93 | |||
94 | $in_fieldset = false; |
||
95 | $first_plugin_fieldset = true; |
||
96 | $first_template_fieldset = true; |
||
97 | foreach($this->configuration->getSettings() as $setting) { |
||
98 | if(is_a($setting, SettingHidden::class)) { |
||
99 | continue; |
||
100 | } else if(is_a($setting, settingFieldset::class)) { |
||
101 | // config setting group |
||
102 | if($in_fieldset) { |
||
103 | echo '</table>'; |
||
104 | echo '</div>'; |
||
105 | echo '</fieldset>'; |
||
106 | } else { |
||
107 | $in_fieldset = true; |
||
108 | } |
||
109 | if($first_plugin_fieldset && $setting->getType() == 'plugin') { |
||
110 | $this->printH1('plugin_settings', $this->getLang('_header_plugin')); |
||
111 | $first_plugin_fieldset = false; |
||
112 | } else if($first_template_fieldset && $setting->getType() == 'template') { |
||
113 | $this->printH1('template_settings', $this->getLang('_header_template')); |
||
114 | $first_template_fieldset = false; |
||
115 | } |
||
116 | echo '<fieldset id="' . $setting->getKey() . '">'; |
||
117 | echo '<legend>' . $setting->prompt($this) . '</legend>'; |
||
118 | echo '<div class="table">'; |
||
119 | echo '<table class="inline">'; |
||
120 | } else { |
||
121 | // config settings |
||
122 | list($label, $input) = $setting->html($this, $this->hasErrors); |
||
123 | |||
124 | $class = $setting->isDefault() |
||
125 | ? ' class="default"' |
||
126 | : ($setting->isProtected() ? ' class="protected"' : ''); |
||
127 | $error = $setting->hasError() |
||
128 | ? ' class="value error"' |
||
129 | : ' class="value"'; |
||
130 | $icon = $setting->caution() |
||
131 | ? '<img src="' . self::IMGDIR . $setting->caution() . '.png" ' . |
||
132 | 'alt="' . $setting->caution() . '" title="' . $this->getLang($setting->caution()) . '" />' |
||
133 | : ''; |
||
134 | |||
135 | echo '<tr' . $class . '>'; |
||
136 | echo '<td class="label">'; |
||
137 | echo '<span class="outkey">' . $setting->getPrettyKey() . '</span>'; |
||
138 | echo $icon . $label; |
||
139 | echo '</td>'; |
||
140 | echo '<td' . $error . '>' . $input . '</td>'; |
||
141 | echo '</tr>'; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | echo '</table>'; |
||
146 | echo '</div>'; |
||
147 | if($in_fieldset) { |
||
148 | echo '</fieldset>'; |
||
149 | } |
||
150 | |||
151 | // show undefined settings list |
||
152 | $undefined_settings = $this->configuration->getUndefined(); |
||
153 | if($allow_debug && !empty($undefined_settings)) { |
||
154 | /** |
||
155 | * Callback for sorting settings |
||
156 | * |
||
157 | * @param Setting $a |
||
158 | * @param Setting $b |
||
159 | * @return int if $a is lower/equal/higher than $b |
||
160 | */ |
||
161 | function settingNaturalComparison($a, $b) { |
||
162 | return strnatcmp($a->getKey(), $b->getKey()); |
||
163 | } |
||
164 | |||
165 | usort($undefined_settings, 'settingNaturalComparison'); |
||
166 | $this->printH1('undefined_settings', $this->getLang('_header_undefined')); |
||
167 | echo '<fieldset>'; |
||
168 | echo '<div class="table">'; |
||
169 | echo '<table class="inline">'; |
||
170 | foreach($undefined_settings as $setting) { |
||
171 | list($label, $input) = $setting->html($this); |
||
172 | echo '<tr>'; |
||
173 | echo '<td class="label">' . $label . '</td>'; |
||
174 | echo '<td>' . $input . '</td>'; |
||
175 | echo '</tr>'; |
||
176 | } |
||
177 | echo '</table>'; |
||
178 | echo '</div>'; |
||
179 | echo '</fieldset>'; |
||
180 | } |
||
181 | |||
182 | // finish up form |
||
183 | echo '<p>'; |
||
184 | echo '<input type="hidden" name="do" value="admin" />'; |
||
185 | echo '<input type="hidden" name="page" value="config" />'; |
||
186 | |||
187 | if(!$this->configuration->isLocked()) { |
||
188 | echo '<input type="hidden" name="save" value="1" />'; |
||
189 | echo '<button type="submit" name="submit" accesskey="s">' . $lang['btn_save'] . '</button>'; |
||
190 | echo '<button type="reset">' . $lang['btn_reset'] . '</button>'; |
||
191 | } |
||
192 | |||
193 | echo '</p>'; |
||
194 | |||
195 | echo '</form>'; |
||
196 | echo '</div>'; |
||
197 | } |
||
198 | |||
283 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: