| Conditions | 35 |
| Paths | > 20000 |
| Total Lines | 353 |
| Code Lines | 231 |
| 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 |
||
| 384 | public function __construct() |
||
| 385 | { |
||
| 386 | /* mandatory requirements follow */ |
||
| 387 | |||
| 388 | $installedPhpVersion = phpversion(); |
||
| 389 | |||
| 390 | $this->addRequirement( |
||
| 391 | version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>='), |
||
| 392 | sprintf('PHP version must be at least %s (%s installed)', self::REQUIRED_PHP_VERSION, $installedPhpVersion), |
||
| 393 | sprintf('You are running PHP version "<strong>%s</strong>", but Symfony needs at least PHP "<strong>%s</strong>" to run. |
||
| 394 | Before using Symfony, upgrade your PHP installation, preferably to the latest version.', |
||
| 395 | $installedPhpVersion, self::REQUIRED_PHP_VERSION), |
||
| 396 | sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION, $installedPhpVersion) |
||
| 397 | ); |
||
| 398 | |||
| 399 | $this->addRequirement( |
||
| 400 | version_compare($installedPhpVersion, '5.3.16', '!='), |
||
| 401 | 'PHP version must not be 5.3.16 as Symfony won\'t work properly with it', |
||
| 402 | 'Install PHP 5.3.17 or newer (or downgrade to an earlier PHP version)' |
||
| 403 | ); |
||
| 404 | |||
| 405 | $this->addRequirement( |
||
| 406 | is_dir(__DIR__.'/../vendor/composer'), |
||
| 407 | 'Vendor libraries must be installed', |
||
| 408 | 'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '. |
||
| 409 | 'Then run "<strong>php composer.phar install</strong>" to install them.' |
||
| 410 | ); |
||
| 411 | |||
| 412 | $cacheDir = is_dir(__DIR__.'/../var/cache') ? __DIR__.'/../var/cache' : __DIR__.'/cache'; |
||
| 413 | |||
| 414 | $this->addRequirement( |
||
| 415 | is_writable($cacheDir), |
||
| 416 | 'app/cache/ or var/cache/ directory must be writable', |
||
| 417 | 'Change the permissions of either "<strong>app/cache/</strong>" or "<strong>var/cache/</strong>" directory so that the web server can write into it.' |
||
| 418 | ); |
||
| 419 | |||
| 420 | $logsDir = is_dir(__DIR__.'/../var/logs') ? __DIR__.'/../var/logs' : __DIR__.'/logs'; |
||
| 421 | |||
| 422 | $this->addRequirement( |
||
| 423 | is_writable($logsDir), |
||
| 424 | 'app/logs/ or var/logs/ directory must be writable', |
||
| 425 | 'Change the permissions of either "<strong>app/logs/</strong>" or "<strong>var/logs/</strong>" directory so that the web server can write into it.' |
||
| 426 | ); |
||
| 427 | |||
| 428 | $this->addPhpIniRequirement( |
||
| 429 | 'date.timezone', true, false, |
||
| 430 | 'date.timezone setting must be set', |
||
| 431 | 'Set the "<strong>date.timezone</strong>" setting in php.ini<a href="#phpini">*</a> (like Europe/Paris).' |
||
| 432 | ); |
||
| 433 | |||
| 434 | if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) { |
||
| 435 | $timezones = array(); |
||
| 436 | foreach (DateTimeZone::listAbbreviations() as $abbreviations) { |
||
| 437 | foreach ($abbreviations as $abbreviation) { |
||
| 438 | $timezones[$abbreviation['timezone_id']] = true; |
||
| 439 | } |
||
| 440 | } |
||
| 441 | |||
| 442 | $this->addRequirement( |
||
| 443 | isset($timezones[@date_default_timezone_get()]), |
||
| 444 | sprintf('Configured default timezone "%s" must be supported by your installation of PHP', @date_default_timezone_get()), |
||
| 445 | 'Your default timezone is not supported by PHP. Check for typos in your <strong>php.ini</strong> file and have a look at the list of deprecated timezones at <a href="http://php.net/manual/en/timezones.others.php">http://php.net/manual/en/timezones.others.php</a>.' |
||
| 446 | ); |
||
| 447 | } |
||
| 448 | |||
| 449 | $this->addRequirement( |
||
| 450 | function_exists('iconv'), |
||
| 451 | 'iconv() must be available', |
||
| 452 | 'Install and enable the <strong>iconv</strong> extension.' |
||
| 453 | ); |
||
| 454 | |||
| 455 | $this->addRequirement( |
||
| 456 | function_exists('json_encode'), |
||
| 457 | 'json_encode() must be available', |
||
| 458 | 'Install and enable the <strong>JSON</strong> extension.' |
||
| 459 | ); |
||
| 460 | |||
| 461 | $this->addRequirement( |
||
| 462 | function_exists('session_start'), |
||
| 463 | 'session_start() must be available', |
||
| 464 | 'Install and enable the <strong>session</strong> extension.' |
||
| 465 | ); |
||
| 466 | |||
| 467 | $this->addRequirement( |
||
| 468 | function_exists('ctype_alpha'), |
||
| 469 | 'ctype_alpha() must be available', |
||
| 470 | 'Install and enable the <strong>ctype</strong> extension.' |
||
| 471 | ); |
||
| 472 | |||
| 473 | $this->addRequirement( |
||
| 474 | function_exists('token_get_all'), |
||
| 475 | 'token_get_all() must be available', |
||
| 476 | 'Install and enable the <strong>Tokenizer</strong> extension.' |
||
| 477 | ); |
||
| 478 | |||
| 479 | $this->addRequirement( |
||
| 480 | function_exists('simplexml_import_dom'), |
||
| 481 | 'simplexml_import_dom() must be available', |
||
| 482 | 'Install and enable the <strong>SimpleXML</strong> extension.' |
||
| 483 | ); |
||
| 484 | |||
| 485 | if (function_exists('apc_store') && ini_get('apc.enabled')) { |
||
| 486 | if (version_compare($installedPhpVersion, '5.4.0', '>=')) { |
||
| 487 | $this->addRequirement( |
||
| 488 | version_compare(phpversion('apc'), '3.1.13', '>='), |
||
| 489 | 'APC version must be at least 3.1.13 when using PHP 5.4', |
||
| 490 | 'Upgrade your <strong>APC</strong> extension (3.1.13+).' |
||
| 491 | ); |
||
| 492 | } else { |
||
| 493 | $this->addRequirement( |
||
| 494 | version_compare(phpversion('apc'), '3.0.17', '>='), |
||
| 495 | 'APC version must be at least 3.0.17', |
||
| 496 | 'Upgrade your <strong>APC</strong> extension (3.0.17+).' |
||
| 497 | ); |
||
| 498 | } |
||
| 499 | } |
||
| 500 | |||
| 501 | $this->addPhpIniRequirement('detect_unicode', false); |
||
| 502 | |||
| 503 | if (extension_loaded('suhosin')) { |
||
| 504 | $this->addPhpIniRequirement( |
||
| 505 | 'suhosin.executor.include.whitelist', |
||
| 506 | create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'), |
||
| 507 | false, |
||
| 508 | 'suhosin.executor.include.whitelist must be configured correctly in php.ini', |
||
| 509 | 'Add "<strong>phar</strong>" to <strong>suhosin.executor.include.whitelist</strong> in php.ini<a href="#phpini">*</a>.' |
||
| 510 | ); |
||
| 511 | } |
||
| 512 | |||
| 513 | if (extension_loaded('xdebug')) { |
||
| 514 | $this->addPhpIniRequirement( |
||
| 515 | 'xdebug.show_exception_trace', false, true |
||
| 516 | ); |
||
| 517 | |||
| 518 | $this->addPhpIniRequirement( |
||
| 519 | 'xdebug.scream', false, true |
||
| 520 | ); |
||
| 521 | |||
| 522 | $this->addPhpIniRecommendation( |
||
| 523 | 'xdebug.max_nesting_level', |
||
| 524 | create_function('$cfgValue', 'return $cfgValue > 100;'), |
||
| 525 | true, |
||
| 526 | 'xdebug.max_nesting_level should be above 100 in php.ini', |
||
| 527 | 'Set "<strong>xdebug.max_nesting_level</strong>" to e.g. "<strong>250</strong>" in php.ini<a href="#phpini">*</a> to stop Xdebug\'s infinite recursion protection erroneously throwing a fatal error in your project.' |
||
| 528 | ); |
||
| 529 | } |
||
| 530 | |||
| 531 | $pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null; |
||
| 532 | |||
| 533 | $this->addRequirement( |
||
| 534 | null !== $pcreVersion, |
||
| 535 | 'PCRE extension must be available', |
||
| 536 | 'Install the <strong>PCRE</strong> extension (version 8.0+).' |
||
| 537 | ); |
||
| 538 | |||
| 539 | if (extension_loaded('mbstring')) { |
||
| 540 | $this->addPhpIniRequirement( |
||
| 541 | 'mbstring.func_overload', |
||
| 542 | create_function('$cfgValue', 'return (int) $cfgValue === 0;'), |
||
| 543 | true, |
||
| 544 | 'string functions should not be overloaded', |
||
| 545 | 'Set "<strong>mbstring.func_overload</strong>" to <strong>0</strong> in php.ini<a href="#phpini">*</a> to disable function overloading by the mbstring extension.' |
||
| 546 | ); |
||
| 547 | } |
||
| 548 | |||
| 549 | /* optional recommendations follow */ |
||
| 550 | |||
| 551 | if (file_exists(__DIR__.'/../vendor/composer')) { |
||
| 552 | require_once __DIR__.'/../vendor/autoload.php'; |
||
| 553 | |||
| 554 | try { |
||
| 555 | $r = new ReflectionClass('Sensio\Bundle\DistributionBundle\SensioDistributionBundle'); |
||
| 556 | |||
| 557 | $contents = file_get_contents(dirname($r->getFileName()).'/Resources/skeleton/app/SymfonyRequirements.php'); |
||
| 558 | } catch (ReflectionException $e) { |
||
| 559 | $contents = ''; |
||
| 560 | } |
||
| 561 | $this->addRecommendation( |
||
| 562 | file_get_contents(__FILE__) === $contents, |
||
| 563 | 'Requirements file should be up-to-date', |
||
| 564 | 'Your requirements file is outdated. Run composer install and re-check your configuration.' |
||
| 565 | ); |
||
| 566 | } |
||
| 567 | |||
| 568 | $this->addRecommendation( |
||
| 569 | version_compare($installedPhpVersion, '5.3.4', '>='), |
||
| 570 | 'You should use at least PHP 5.3.4 due to PHP bug #52083 in earlier versions', |
||
| 571 | 'Your project might malfunction randomly due to PHP bug #52083 ("Notice: Trying to get property of non-object"). Install PHP 5.3.4 or newer.' |
||
| 572 | ); |
||
| 573 | |||
| 574 | $this->addRecommendation( |
||
| 575 | version_compare($installedPhpVersion, '5.3.8', '>='), |
||
| 576 | 'When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156', |
||
| 577 | 'Install PHP 5.3.8 or newer if your project uses annotations.' |
||
| 578 | ); |
||
| 579 | |||
| 580 | $this->addRecommendation( |
||
| 581 | version_compare($installedPhpVersion, '5.4.0', '!='), |
||
| 582 | 'You should not use PHP 5.4.0 due to the PHP bug #61453', |
||
| 583 | 'Your project might not work properly due to the PHP bug #61453 ("Cannot dump definitions which have method calls"). Install PHP 5.4.1 or newer.' |
||
| 584 | ); |
||
| 585 | |||
| 586 | $this->addRecommendation( |
||
| 587 | version_compare($installedPhpVersion, '5.4.11', '>='), |
||
| 588 | 'When using the logout handler from the Symfony Security Component, you should have at least PHP 5.4.11 due to PHP bug #63379 (as a workaround, you can also set invalidate_session to false in the security logout handler configuration)', |
||
| 589 | 'Install PHP 5.4.11 or newer if your project uses the logout handler from the Symfony Security Component.' |
||
| 590 | ); |
||
| 591 | |||
| 592 | $this->addRecommendation( |
||
| 593 | (version_compare($installedPhpVersion, '5.3.18', '>=') && version_compare($installedPhpVersion, '5.4.0', '<')) |
||
| 594 | || |
||
| 595 | version_compare($installedPhpVersion, '5.4.8', '>='), |
||
| 596 | 'You should use PHP 5.3.18+ or PHP 5.4.8+ to always get nice error messages for fatal errors in the development environment due to PHP bug #61767/#60909', |
||
| 597 | 'Install PHP 5.3.18+ or PHP 5.4.8+ if you want nice error messages for all fatal errors in the development environment.' |
||
| 598 | ); |
||
| 599 | |||
| 600 | if (null !== $pcreVersion) { |
||
| 601 | $this->addRecommendation( |
||
| 602 | $pcreVersion >= 8.0, |
||
| 603 | sprintf('PCRE extension should be at least version 8.0 (%s installed)', $pcreVersion), |
||
| 604 | '<strong>PCRE 8.0+</strong> is preconfigured in PHP since 5.3.2 but you are using an outdated version of it. Symfony probably works anyway but it is recommended to upgrade your PCRE extension.' |
||
| 605 | ); |
||
| 606 | } |
||
| 607 | |||
| 608 | $this->addRecommendation( |
||
| 609 | class_exists('DomDocument'), |
||
| 610 | 'PHP-DOM and PHP-XML modules should be installed', |
||
| 611 | 'Install and enable the <strong>PHP-DOM</strong> and the <strong>PHP-XML</strong> modules.' |
||
| 612 | ); |
||
| 613 | |||
| 614 | $this->addRecommendation( |
||
| 615 | function_exists('mb_strlen'), |
||
| 616 | 'mb_strlen() should be available', |
||
| 617 | 'Install and enable the <strong>mbstring</strong> extension.' |
||
| 618 | ); |
||
| 619 | |||
| 620 | $this->addRecommendation( |
||
| 621 | function_exists('iconv'), |
||
| 622 | 'iconv() should be available', |
||
| 623 | 'Install and enable the <strong>iconv</strong> extension.' |
||
| 624 | ); |
||
| 625 | |||
| 626 | $this->addRecommendation( |
||
| 627 | function_exists('utf8_decode'), |
||
| 628 | 'utf8_decode() should be available', |
||
| 629 | 'Install and enable the <strong>XML</strong> extension.' |
||
| 630 | ); |
||
| 631 | |||
| 632 | $this->addRecommendation( |
||
| 633 | function_exists('filter_var'), |
||
| 634 | 'filter_var() should be available', |
||
| 635 | 'Install and enable the <strong>filter</strong> extension.' |
||
| 636 | ); |
||
| 637 | |||
| 638 | if (!defined('PHP_WINDOWS_VERSION_BUILD')) { |
||
| 639 | $this->addRecommendation( |
||
| 640 | function_exists('posix_isatty'), |
||
| 641 | 'posix_isatty() should be available', |
||
| 642 | 'Install and enable the <strong>php_posix</strong> extension (used to colorize the CLI output).' |
||
| 643 | ); |
||
| 644 | } |
||
| 645 | |||
| 646 | $this->addRecommendation( |
||
| 647 | extension_loaded('intl'), |
||
| 648 | 'intl extension should be available', |
||
| 649 | 'Install and enable the <strong>intl</strong> extension (used for validators).' |
||
| 650 | ); |
||
| 651 | |||
| 652 | if (extension_loaded('intl')) { |
||
| 653 | // in some WAMP server installations, new Collator() returns null |
||
| 654 | $this->addRecommendation( |
||
| 655 | null !== new Collator('fr_FR'), |
||
| 656 | 'intl extension should be correctly configured', |
||
| 657 | 'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.' |
||
| 658 | ); |
||
| 659 | |||
| 660 | // check for compatible ICU versions (only done when you have the intl extension) |
||
| 661 | if (defined('INTL_ICU_VERSION')) { |
||
| 662 | $version = INTL_ICU_VERSION; |
||
| 663 | } else { |
||
| 664 | $reflector = new ReflectionExtension('intl'); |
||
| 665 | |||
| 666 | ob_start(); |
||
| 667 | $reflector->info(); |
||
| 668 | $output = strip_tags(ob_get_clean()); |
||
| 669 | |||
| 670 | preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches); |
||
| 671 | $version = $matches[1]; |
||
| 672 | } |
||
| 673 | |||
| 674 | $this->addRecommendation( |
||
| 675 | version_compare($version, '4.0', '>='), |
||
| 676 | 'intl ICU version should be at least 4+', |
||
| 677 | 'Upgrade your <strong>intl</strong> extension with a newer ICU version (4+).' |
||
| 678 | ); |
||
| 679 | |||
| 680 | $this->addPhpIniRecommendation( |
||
| 681 | 'intl.error_level', |
||
| 682 | create_function('$cfgValue', 'return (int) $cfgValue === 0;'), |
||
| 683 | true, |
||
| 684 | 'intl.error_level should be 0 in php.ini', |
||
| 685 | 'Set "<strong>intl.error_level</strong>" to "<strong>0</strong>" in php.ini<a href="#phpini">*</a> to inhibit the messages when an error occurs in ICU functions.' |
||
| 686 | ); |
||
| 687 | } |
||
| 688 | |||
| 689 | $accelerator = |
||
| 690 | (extension_loaded('eaccelerator') && ini_get('eaccelerator.enable')) |
||
| 691 | || |
||
| 692 | (extension_loaded('apc') && ini_get('apc.enabled')) |
||
| 693 | || |
||
| 694 | (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.enable')) |
||
| 695 | || |
||
| 696 | (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) |
||
| 697 | || |
||
| 698 | (extension_loaded('xcache') && ini_get('xcache.cacher')) |
||
| 699 | || |
||
| 700 | (extension_loaded('wincache') && ini_get('wincache.ocenabled')) |
||
| 701 | ; |
||
| 702 | |||
| 703 | $this->addRecommendation( |
||
| 704 | $accelerator, |
||
| 705 | 'a PHP accelerator should be installed', |
||
| 706 | 'Install and/or enable a <strong>PHP accelerator</strong> (highly recommended).' |
||
| 707 | ); |
||
| 708 | |||
| 709 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
||
| 710 | $this->addRecommendation( |
||
| 711 | $this->getRealpathCacheSize() > 1000, |
||
| 712 | 'realpath_cache_size should be above 1024 in php.ini', |
||
| 713 | 'Set "<strong>realpath_cache_size</strong>" to e.g. "<strong>1024</strong>" in php.ini<a href="#phpini">*</a> to improve performance on windows.' |
||
| 714 | ); |
||
| 715 | } |
||
| 716 | |||
| 717 | $this->addPhpIniRecommendation('short_open_tag', false); |
||
| 718 | |||
| 719 | $this->addPhpIniRecommendation('magic_quotes_gpc', false, true); |
||
| 720 | |||
| 721 | $this->addPhpIniRecommendation('register_globals', false, true); |
||
| 722 | |||
| 723 | $this->addPhpIniRecommendation('session.auto_start', false); |
||
| 724 | |||
| 725 | $this->addRecommendation( |
||
| 726 | class_exists('PDO'), |
||
| 727 | 'PDO should be installed', |
||
| 728 | 'Install <strong>PDO</strong> (mandatory for Doctrine).' |
||
| 729 | ); |
||
| 730 | |||
| 731 | if (class_exists('PDO')) { |
||
| 732 | $drivers = PDO::getAvailableDrivers(); |
||
| 733 | $this->addRecommendation( |
||
| 734 | count($drivers) > 0, |
||
| 735 | sprintf('PDO should have some drivers installed (currently available: %s)', count($drivers) ? implode(', ', $drivers) : 'none'), |
||
| 736 | 'Install <strong>PDO drivers</strong> (mandatory for Doctrine).' |
||
| 737 | ); |
||
| 765 |