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