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