Conditions | 43 |
Paths | > 20000 |
Total Lines | 189 |
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 |
||
117 | function check(){ |
||
118 | global $conf; |
||
119 | global $INFO; |
||
120 | /* @var Input $INPUT */ |
||
121 | global $INPUT; |
||
122 | |||
123 | if ($INFO['isadmin'] || $INFO['ismanager']){ |
||
124 | msg('DokuWiki version: '.getVersion(),1); |
||
125 | |||
126 | if(version_compare(phpversion(),'5.6.0','<')){ |
||
127 | msg('Your PHP version is too old ('.phpversion().' vs. 5.6.0+ needed)',-1); |
||
128 | }else{ |
||
129 | msg('PHP version '.phpversion(),1); |
||
130 | } |
||
131 | } else { |
||
132 | if(version_compare(phpversion(),'5.6.0','<')){ |
||
133 | msg('Your PHP version is too old',-1); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | $mem = (int) php_to_byte(ini_get('memory_limit')); |
||
138 | if($mem){ |
||
139 | if ($mem === -1) { |
||
140 | msg('PHP memory is unlimited', 1); |
||
141 | } else if ($mem < 16777216) { |
||
142 | msg('PHP is limited to less than 16MB RAM (' . filesize_h($mem) . '). |
||
143 | Increase memory_limit in php.ini', -1); |
||
144 | } else if ($mem < 20971520) { |
||
145 | msg('PHP is limited to less than 20MB RAM (' . filesize_h($mem) . '), |
||
146 | you might encounter problems with bigger pages. Increase memory_limit in php.ini', -1); |
||
147 | } else if ($mem < 33554432) { |
||
148 | msg('PHP is limited to less than 32MB RAM (' . filesize_h($mem) . '), |
||
149 | but that should be enough in most cases. If not, increase memory_limit in php.ini', 0); |
||
150 | } else { |
||
151 | msg('More than 32MB RAM (' . filesize_h($mem) . ') available.', 1); |
||
152 | } |
||
153 | } |
||
154 | |||
155 | if(is_writable($conf['changelog'])){ |
||
156 | msg('Changelog is writable',1); |
||
157 | }else{ |
||
158 | if (file_exists($conf['changelog'])) { |
||
159 | msg('Changelog is not writable',-1); |
||
160 | } |
||
161 | } |
||
162 | |||
163 | if (isset($conf['changelog_old']) && file_exists($conf['changelog_old'])) { |
||
164 | msg('Old changelog exists', 0); |
||
165 | } |
||
166 | |||
167 | if (file_exists($conf['changelog'].'_failed')) { |
||
168 | msg('Importing old changelog failed', -1); |
||
169 | } else if (file_exists($conf['changelog'].'_importing')) { |
||
170 | msg('Importing old changelog now.', 0); |
||
171 | } else if (file_exists($conf['changelog'].'_import_ok')) { |
||
172 | msg('Old changelog imported', 1); |
||
173 | if (!plugin_isdisabled('importoldchangelog')) { |
||
174 | msg('Importoldchangelog plugin not disabled after import', -1); |
||
175 | } |
||
176 | } |
||
177 | |||
178 | if(is_writable(DOKU_CONF)){ |
||
179 | msg('conf directory is writable',1); |
||
180 | }else{ |
||
181 | msg('conf directory is not writable',-1); |
||
182 | } |
||
183 | |||
184 | if($conf['authtype'] == 'plain'){ |
||
185 | global $config_cascade; |
||
186 | if(is_writable($config_cascade['plainauth.users']['default'])){ |
||
187 | msg('conf/users.auth.php is writable',1); |
||
188 | }else{ |
||
189 | msg('conf/users.auth.php is not writable',0); |
||
190 | } |
||
191 | } |
||
192 | |||
193 | if(function_exists('mb_strpos')){ |
||
194 | if(defined('UTF8_NOMBSTRING')){ |
||
195 | msg('mb_string extension is available but will not be used',0); |
||
196 | }else{ |
||
197 | msg('mb_string extension is available and will be used',1); |
||
198 | if(ini_get('mbstring.func_overload') != 0){ |
||
199 | msg('mb_string function overloading is enabled, this will cause problems and should be disabled',-1); |
||
200 | } |
||
201 | } |
||
202 | }else{ |
||
203 | msg('mb_string extension not available - PHP only replacements will be used',0); |
||
204 | } |
||
205 | |||
206 | if (!UTF8_PREGSUPPORT) { |
||
207 | msg('PHP is missing UTF-8 support in Perl-Compatible Regular Expressions (PCRE)', -1); |
||
208 | } |
||
209 | if (!UTF8_PROPERTYSUPPORT) { |
||
210 | msg('PHP is missing Unicode properties support in Perl-Compatible Regular Expressions (PCRE)', -1); |
||
211 | } |
||
212 | |||
213 | $loc = setlocale(LC_ALL, 0); |
||
214 | if(!$loc){ |
||
215 | msg('No valid locale is set for your PHP setup. You should fix this',-1); |
||
216 | }elseif(stripos($loc,'utf') === false){ |
||
217 | msg('Your locale <code>'.hsc($loc).'</code> seems not to be a UTF-8 locale, |
||
218 | you should fix this if you encounter problems.',0); |
||
219 | }else{ |
||
220 | msg('Valid locale '.hsc($loc).' found.', 1); |
||
221 | } |
||
222 | |||
223 | if($conf['allowdebug']){ |
||
224 | msg('Debugging support is enabled. If you don\'t need it you should set $conf[\'allowdebug\'] = 0',-1); |
||
225 | }else{ |
||
226 | msg('Debugging support is disabled',1); |
||
227 | } |
||
228 | |||
229 | if($INFO['userinfo']['name']){ |
||
230 | msg('You are currently logged in as '.$INPUT->server->str('REMOTE_USER').' ('.$INFO['userinfo']['name'].')',0); |
||
231 | msg('You are part of the groups '.join($INFO['userinfo']['grps'],', '),0); |
||
232 | }else{ |
||
233 | msg('You are currently not logged in',0); |
||
234 | } |
||
235 | |||
236 | msg('Your current permission for this page is '.$INFO['perm'],0); |
||
237 | |||
238 | if (file_exists($INFO['filepath']) && is_writable($INFO['filepath'])) { |
||
239 | msg('The current page is writable by the webserver', 1); |
||
240 | } elseif (!file_exists($INFO['filepath']) && is_writable(dirname($INFO['filepath']))) { |
||
241 | msg('The current page can be created by the webserver', 1); |
||
242 | } else { |
||
243 | msg('The current page is not writable by the webserver', -1); |
||
244 | } |
||
245 | |||
246 | if ($INFO['writable']) { |
||
247 | msg('The current page is writable by you', 1); |
||
248 | } else { |
||
249 | msg('The current page is not writable by you', -1); |
||
250 | } |
||
251 | |||
252 | // Check for corrupted search index |
||
253 | $lengths = idx_listIndexLengths(); |
||
254 | $index_corrupted = false; |
||
255 | foreach ($lengths as $length) { |
||
256 | if (count(idx_getIndex('w', $length)) != count(idx_getIndex('i', $length))) { |
||
257 | $index_corrupted = true; |
||
258 | break; |
||
259 | } |
||
260 | } |
||
261 | |||
262 | foreach (idx_getIndex('metadata', '') as $index) { |
||
263 | if (count(idx_getIndex($index.'_w', '')) != count(idx_getIndex($index.'_i', ''))) { |
||
264 | $index_corrupted = true; |
||
265 | break; |
||
266 | } |
||
267 | } |
||
268 | |||
269 | if($index_corrupted) { |
||
270 | msg( |
||
271 | 'The search index is corrupted. It might produce wrong results and most |
||
272 | probably needs to be rebuilt. See |
||
273 | <a href="http://www.dokuwiki.org/faq:searchindex">faq:searchindex</a> |
||
274 | for ways to rebuild the search index.', -1 |
||
275 | ); |
||
276 | } elseif(!empty($lengths)) { |
||
277 | msg('The search index seems to be working', 1); |
||
278 | } else { |
||
279 | msg( |
||
280 | 'The search index is empty. See |
||
281 | <a href="http://www.dokuwiki.org/faq:searchindex">faq:searchindex</a> |
||
282 | for help on how to fix the search index. If the default indexer |
||
283 | isn\'t used or the wiki is actually empty this is normal.' |
||
284 | ); |
||
285 | } |
||
286 | |||
287 | // rough time check |
||
288 | $http = new DokuHTTPClient(); |
||
289 | $http->max_redirect = 0; |
||
290 | $http->timeout = 3; |
||
291 | $http->sendRequest('http://www.dokuwiki.org', '', 'HEAD'); |
||
292 | $now = time(); |
||
293 | if(isset($http->resp_headers['date'])) { |
||
294 | $time = strtotime($http->resp_headers['date']); |
||
295 | $diff = $time - $now; |
||
296 | |||
297 | if(abs($diff) < 4) { |
||
298 | msg("Server time seems to be okay. Diff: {$diff}s", 1); |
||
299 | } else { |
||
300 | msg("Your server's clock seems to be out of sync! |
||
301 | Consider configuring a sync with a NTP server. Diff: {$diff}s"); |
||
302 | } |
||
303 | } |
||
304 | |||
305 | } |
||
306 | |||
546 |
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: