Conditions | 23 |
Paths | > 20000 |
Total Lines | 385 |
Code Lines | 315 |
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 |
||
280 | public function get_php_data() |
||
281 | { |
||
282 | $array = []; |
||
283 | |||
284 | // General Functions |
||
285 | |||
286 | $version = phpversion(); |
||
287 | $status = $version > REQUIRED_PHP_VERSION ? self::STATUS_OK : self::STATUS_ERROR; |
||
288 | $array[] = $this->build_setting( |
||
289 | $status, |
||
290 | '[PHP]', |
||
291 | 'phpversion()', |
||
292 | 'https://php.net/manual/en/function.phpversion.php', |
||
293 | phpversion(), |
||
294 | '>= '.REQUIRED_PHP_VERSION, |
||
295 | null, |
||
296 | get_lang('PHP version') |
||
297 | ); |
||
298 | |||
299 | $setting = ini_get('output_buffering'); |
||
300 | $req_setting = 1; |
||
301 | $status = $setting >= $req_setting ? self::STATUS_OK : self::STATUS_ERROR; |
||
302 | $array[] = $this->build_setting( |
||
303 | $status, |
||
304 | '[INI]', |
||
305 | 'output_buffering', |
||
306 | 'https://php.net/manual/en/outcontrol.configuration.php#ini.output-buffering', |
||
307 | $setting, |
||
308 | $req_setting, |
||
309 | 'on_off', |
||
310 | get_lang('Output buffering setting is "On" for being enabled or "Off" for being disabled. This setting also may be enabled through an integer value (4096 for example) which is the output buffer size.') |
||
311 | ); |
||
312 | |||
313 | $setting = ini_get('file_uploads'); |
||
314 | $req_setting = 1; |
||
315 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR; |
||
316 | $array[] = $this->build_setting( |
||
317 | $status, |
||
318 | '[INI]', |
||
319 | 'file_uploads', |
||
320 | 'https://php.net/manual/en/ini.core.php#ini.file-uploads', |
||
321 | $setting, |
||
322 | $req_setting, |
||
323 | 'on_off', |
||
324 | get_lang('File uploads indicate whether file uploads are authorized at all') |
||
325 | ); |
||
326 | |||
327 | $setting = ini_get('magic_quotes_runtime'); |
||
328 | $req_setting = 0; |
||
329 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR; |
||
330 | $array[] = $this->build_setting( |
||
331 | $status, |
||
332 | '[INI]', |
||
333 | 'magic_quotes_runtime', |
||
334 | 'https://php.net/manual/en/ini.core.php#ini.magic-quotes-runtime', |
||
335 | $setting, |
||
336 | $req_setting, |
||
337 | 'on_off', |
||
338 | get_lang('This is a highly unrecommended feature which converts values returned by all functions that returned external values to slash-escaped values. This feature should *not* be enabled.') |
||
339 | ); |
||
340 | |||
341 | $setting = ini_get('safe_mode'); |
||
342 | $req_setting = 0; |
||
343 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING; |
||
344 | $array[] = $this->build_setting( |
||
345 | $status, |
||
346 | '[INI]', |
||
347 | 'safe_mode', |
||
348 | 'https://php.net/manual/en/ini.core.php#ini.safe-mode', |
||
349 | $setting, |
||
350 | $req_setting, |
||
351 | 'on_off', |
||
352 | get_lang('Safe mode is a deprecated PHP feature which (badly) limits the access of PHP scripts to other resources. It is recommended to leave it off.') |
||
353 | ); |
||
354 | |||
355 | $setting = ini_get('register_globals'); |
||
356 | $req_setting = 0; |
||
357 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR; |
||
358 | $array[] = $this->build_setting( |
||
359 | $status, |
||
360 | '[INI]', |
||
361 | 'register_globals', |
||
362 | 'https://php.net/manual/en/ini.core.php#ini.register-globals', |
||
363 | $setting, |
||
364 | $req_setting, |
||
365 | 'on_off', |
||
366 | get_lang('Whether to use the register globals feature or not. Using it represents potential security risks with this software.') |
||
367 | ); |
||
368 | |||
369 | $setting = ini_get('short_open_tag'); |
||
370 | $req_setting = 0; |
||
371 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING; |
||
372 | $array[] = $this->build_setting( |
||
373 | $status, |
||
374 | '[INI]', |
||
375 | 'short_open_tag', |
||
376 | 'https://php.net/manual/en/ini.core.php#ini.short-open-tag', |
||
377 | $setting, |
||
378 | $req_setting, |
||
379 | 'on_off', |
||
380 | get_lang('Whether to allow for short open tags to be used or not. This feature should not be used.') |
||
381 | ); |
||
382 | |||
383 | $setting = ini_get('magic_quotes_gpc'); |
||
384 | $req_setting = 0; |
||
385 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR; |
||
386 | $array[] = $this->build_setting( |
||
387 | $status, |
||
388 | '[INI]', |
||
389 | 'magic_quotes_gpc', |
||
390 | 'https://php.net/manual/en/ini.core.php#ini.magic_quotes_gpc', |
||
391 | $setting, |
||
392 | $req_setting, |
||
393 | 'on_off', |
||
394 | get_lang('Whether to automatically escape values from GET, POST and COOKIES arrays. A similar feature is provided for the required data inside this software, so using it provokes double slash-escaping of values.') |
||
395 | ); |
||
396 | |||
397 | $setting = ini_get('display_errors'); |
||
398 | $req_setting = 0; |
||
399 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING; |
||
400 | $array[] = $this->build_setting( |
||
401 | $status, |
||
402 | '[INI]', |
||
403 | 'display_errors', |
||
404 | 'https://php.net/manual/en/ini.core.php#ini.display_errors', |
||
405 | $setting, |
||
406 | $req_setting, |
||
407 | 'on_off', |
||
408 | get_lang('Show errors on screen. Turn this on on development servers, off on production servers.') |
||
409 | ); |
||
410 | |||
411 | $setting = ini_get('default_charset'); |
||
412 | if ('' == $setting) { |
||
413 | $setting = null; |
||
414 | } |
||
415 | $req_setting = 'UTF-8'; |
||
416 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR; |
||
417 | $array[] = $this->build_setting( |
||
418 | $status, |
||
419 | '[INI]', |
||
420 | 'default_charset', |
||
421 | 'https://php.net/manual/en/ini.core.php#ini.default-charset', |
||
422 | $setting, |
||
423 | $req_setting, |
||
424 | null, |
||
425 | get_lang('The default character set to be sent when returning pages') |
||
426 | ); |
||
427 | |||
428 | $setting = ini_get('max_execution_time'); |
||
429 | $req_setting = '300 ('.get_lang('minimum').')'; |
||
430 | $status = $setting >= 300 ? self::STATUS_OK : self::STATUS_WARNING; |
||
431 | $array[] = $this->build_setting( |
||
432 | $status, |
||
433 | '[INI]', |
||
434 | 'max_execution_time', |
||
435 | 'https://php.net/manual/en/ini.core.php#ini.max-execution-time', |
||
436 | $setting, |
||
437 | $req_setting, |
||
438 | null, |
||
439 | get_lang('Maximum time a script can take to execute. If using more than that, the script is abandoned to avoid slowing down other users.') |
||
440 | ); |
||
441 | |||
442 | $setting = ini_get('max_input_time'); |
||
443 | $req_setting = '300 ('.get_lang('minimum').')'; |
||
444 | $status = $setting >= 300 ? self::STATUS_OK : self::STATUS_WARNING; |
||
445 | $array[] = $this->build_setting( |
||
446 | $status, |
||
447 | '[INI]', |
||
448 | 'max_input_time', |
||
449 | 'https://php.net/manual/en/ini.core.php#ini.max-input-time', |
||
450 | $setting, |
||
451 | $req_setting, |
||
452 | null, |
||
453 | get_lang('The maximum time allowed for a form to be processed by the server. If it takes longer, the process is abandonned and a blank page is returned.') |
||
454 | ); |
||
455 | |||
456 | $setting = ini_get('memory_limit'); |
||
457 | $req_setting = '>= '.REQUIRED_MIN_MEMORY_LIMIT.'M'; |
||
458 | $status = self::STATUS_ERROR; |
||
459 | if ((float) $setting >= REQUIRED_MIN_MEMORY_LIMIT) { |
||
460 | $status = self::STATUS_OK; |
||
461 | } |
||
462 | $array[] = $this->build_setting( |
||
463 | $status, |
||
464 | '[INI]', |
||
465 | 'memory_limit', |
||
466 | 'https://php.net/manual/en/ini.core.php#ini.memory-limit', |
||
467 | $setting, |
||
468 | $req_setting, |
||
469 | null, |
||
470 | get_lang('Maximum memory limit for one single script run. If the memory needed is higher, the process will stop to avoid consuming all the server\'s available memory and thus slowing down other users.') |
||
471 | ); |
||
472 | |||
473 | $setting = ini_get('post_max_size'); |
||
474 | $req_setting = '>= '.REQUIRED_MIN_POST_MAX_SIZE.'M'; |
||
475 | $status = self::STATUS_ERROR; |
||
476 | if ((float) $setting >= REQUIRED_MIN_POST_MAX_SIZE) { |
||
477 | $status = self::STATUS_OK; |
||
478 | } |
||
479 | $array[] = $this->build_setting( |
||
480 | $status, |
||
481 | '[INI]', |
||
482 | 'post_max_size', |
||
483 | 'https://php.net/manual/en/ini.core.php#ini.post-max-size', |
||
484 | $setting, |
||
485 | $req_setting, |
||
486 | null, |
||
487 | get_lang('This is the maximum size of uploads through forms using the POST method (i.e. classical file upload forms)') |
||
488 | ); |
||
489 | |||
490 | $setting = ini_get('upload_max_filesize'); |
||
491 | $req_setting = '>= '.REQUIRED_MIN_UPLOAD_MAX_FILESIZE.'M'; |
||
492 | $status = self::STATUS_ERROR; |
||
493 | if ((float) $setting >= REQUIRED_MIN_UPLOAD_MAX_FILESIZE) { |
||
494 | $status = self::STATUS_OK; |
||
495 | } |
||
496 | $array[] = $this->build_setting( |
||
497 | $status, |
||
498 | '[INI]', |
||
499 | 'upload_max_filesize', |
||
500 | 'https://php.net/manual/en/ini.core.php#ini.upload_max_filesize', |
||
501 | $setting, |
||
502 | $req_setting, |
||
503 | null, |
||
504 | get_lang('Maximum volume of an uploaded file. This setting should, most of the time, be matched with the post_max_size variable.') |
||
505 | ); |
||
506 | |||
507 | $setting = ini_get('upload_tmp_dir'); |
||
508 | $status = self::STATUS_OK; |
||
509 | $array[] = $this->build_setting( |
||
510 | $status, |
||
511 | '[INI]', |
||
512 | 'upload_tmp_dir', |
||
513 | 'https://php.net/manual/en/ini.core.php#ini.upload_tmp_dir', |
||
514 | $setting, |
||
515 | '', |
||
516 | null, |
||
517 | get_lang('The temporary upload directory is a space on the server where files are uploaded before being filtered and treated by PHP.') |
||
518 | ); |
||
519 | |||
520 | $setting = ini_get('variables_order'); |
||
521 | $req_setting = 'GPCS'; |
||
522 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR; |
||
523 | $array[] = $this->build_setting( |
||
524 | $status, |
||
525 | '[INI]', |
||
526 | 'variables_order', |
||
527 | 'https://php.net/manual/en/ini.core.php#ini.variables-order', |
||
528 | $setting, |
||
529 | $req_setting, |
||
530 | null, |
||
531 | get_lang('The order of precedence of Environment, GET, POST, COOKIES and SESSION variables') |
||
532 | ); |
||
533 | |||
534 | $setting = ini_get('session.gc_maxlifetime'); |
||
535 | $req_setting = '4320'; |
||
536 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING; |
||
537 | $array[] = $this->build_setting( |
||
538 | $status, |
||
539 | '[SESSION]', |
||
540 | 'session.gc_maxlifetime', |
||
541 | 'https://php.net/manual/en/ini.core.php#session.gc-maxlifetime', |
||
542 | $setting, |
||
543 | $req_setting, |
||
544 | null, |
||
545 | get_lang('The session garbage collector maximum lifetime indicates which maximum time is given between two runs of the garbage collector.') |
||
546 | ); |
||
547 | |||
548 | if (api_check_browscap()) { |
||
549 | $setting = true; |
||
550 | } else { |
||
551 | $setting = false; |
||
552 | } |
||
553 | $req_setting = true; |
||
554 | $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING; |
||
555 | $array[] = $this->build_setting( |
||
556 | $status, |
||
557 | '[INI]', |
||
558 | 'browscap', |
||
559 | 'https://php.net/manual/en/misc.configuration.php#ini.browscap', |
||
560 | $setting, |
||
561 | $req_setting, |
||
562 | 'on_off', |
||
563 | get_lang('Browscap loading browscap.ini file that contains a large amount of data on the browser and its capabilities, so it can be used by the function get_browser () PHP') |
||
564 | ); |
||
565 | |||
566 | // Extensions |
||
567 | $extensions = [ |
||
568 | 'gd' => [ |
||
569 | 'link' => 'https://php.net/gd', |
||
570 | 'expected' => 1, |
||
571 | 'comment' => get_lang('This extension must be loaded.'), |
||
572 | ], |
||
573 | 'pdo_mysql' => [ |
||
574 | 'link' => 'https://php.net/manual/en/ref.pdo-mysql.php', |
||
575 | 'expected' => 1, |
||
576 | 'comment' => get_lang('This extension must be loaded.'), |
||
577 | ], |
||
578 | 'pcre' => [ |
||
579 | 'link' => 'https://php.net/pcre', |
||
580 | 'expected' => 1, |
||
581 | 'comment' => get_lang('This extension must be loaded.'), |
||
582 | ], |
||
583 | 'session' => [ |
||
584 | 'link' => 'https://php.net/session', |
||
585 | 'expected' => 1, |
||
586 | 'comment' => get_lang('This extension must be loaded.'), |
||
587 | ], |
||
588 | 'standard' => [ |
||
589 | 'link' => 'https://php.net/spl', |
||
590 | 'expected' => 1, |
||
591 | 'comment' => get_lang('This extension must be loaded.'), |
||
592 | ], |
||
593 | 'zlib' => [ |
||
594 | 'link' => 'https://php.net/zlib', |
||
595 | 'expected' => 1, |
||
596 | 'comment' => get_lang('ExtensionMustBeLoaded'), |
||
597 | ], |
||
598 | 'curl' => [ |
||
599 | 'link' => 'https://php.net/curl', |
||
600 | 'expected' => 1, |
||
601 | 'comment' => get_lang('ExtensionMustBeLoaded'), |
||
602 | ], |
||
603 | 'fileinfo' => [ |
||
604 | 'link' => 'https://php.net/fileinfo', |
||
605 | 'expected' => 1, |
||
606 | 'comment' => get_lang('ExtensionMustBeLoaded'), |
||
607 | ], |
||
608 | 'xsl' => [ |
||
609 | 'link' => 'https://php.net/xsl', |
||
610 | 'expected' => 2, |
||
611 | 'comment' => get_lang('ExtensionShouldBeLoaded'), |
||
612 | ], |
||
613 | 'Zend OPcache' => [ |
||
614 | 'link' => 'https://php.net/opcache', |
||
615 | 'expected' => 2, |
||
616 | 'comment' => get_lang('This extension should be loaded.'), |
||
617 | ], |
||
618 | 'apcu' => [ |
||
619 | 'link' => 'https://php.net/apcu', |
||
620 | 'expected' => 2, |
||
621 | 'comment' => get_lang('This extension should be loaded.'), |
||
622 | ], |
||
623 | 'exif' => [ |
||
624 | 'link' => 'https://www.php.net/exif', |
||
625 | 'expected' => 1, |
||
626 | 'comment' => get_lang('This extension should be loaded.'), |
||
627 | ], |
||
628 | 'mbstring' => [ |
||
629 | 'link' => 'https://www.php.net/mbstring', |
||
630 | 'expected' => 1, |
||
631 | 'comment' => get_lang('This extension should be loaded.'), |
||
632 | ], |
||
633 | 'openssl' => [ //required only for DKIM e-mail signatures |
||
634 | 'link' => 'https://php.net/openssl', |
||
635 | 'expected' => 2, |
||
636 | 'comment' => get_lang('ExtensionShouldBeLoaded'), |
||
637 | ], |
||
638 | 'bcmath' => [ |
||
639 | 'link' => 'https://php.net/bcmath', |
||
640 | 'expected' => 2, |
||
641 | 'comment' => get_lang('ExtensionShouldBeLoaded'), |
||
642 | ], |
||
643 | ]; |
||
644 | |||
645 | foreach ($extensions as $extension => $data) { |
||
646 | $url = $data['link']; |
||
647 | $expected_value = $data['expected']; |
||
648 | $comment = $data['comment']; |
||
649 | |||
650 | $loaded = extension_loaded($extension); |
||
651 | $status = $loaded ? self::STATUS_OK : self::STATUS_ERROR; |
||
652 | $array[] = $this->build_setting( |
||
653 | $status, |
||
654 | '[EXTENSION]', |
||
655 | get_lang('Extension loaded').': '.$extension, |
||
656 | $url, |
||
657 | $loaded, |
||
658 | $expected_value, |
||
659 | 'yes_no_optional', |
||
660 | $comment |
||
661 | ); |
||
662 | } |
||
663 | |||
664 | return $array; |
||
665 | } |
||
1022 |