Conditions | 20 |
Paths | 4608 |
Total Lines | 257 |
Code Lines | 165 |
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 | $baseDir = basename(__DIR__); |
||
413 | |||
414 | $this->addRequirement( |
||
415 | is_writable(__DIR__.'/cache'), |
||
416 | "$baseDir/cache/ directory must be writable", |
||
417 | "Change the permissions of the \"<strong>$baseDir/cache/</strong>\" directory so that the web server can write into it." |
||
418 | ); |
||
419 | |||
420 | $this->addRequirement( |
||
421 | is_writable(__DIR__.'/logs'), |
||
422 | "$baseDir/logs/ directory must be writable", |
||
423 | "Change the permissions of the \"<strong>$baseDir/logs/</strong>\" directory so that the web server can write into it." |
||
424 | ); |
||
425 | |||
426 | $this->addPhpIniRequirement( |
||
427 | 'date.timezone', true, false, |
||
428 | 'date.timezone setting must be set', |
||
429 | 'Set the "<strong>date.timezone</strong>" setting in php.ini<a href="#phpini">*</a> (like Europe/Paris).' |
||
430 | ); |
||
431 | |||
432 | if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) { |
||
433 | $this->addRequirement( |
||
434 | (in_array(date_default_timezone_get(), DateTimeZone::listIdentifiers())), |
||
435 | sprintf('Configured default timezone "%s" must be supported by your installation of PHP', date_default_timezone_get()), |
||
436 | '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>.' |
||
437 | ); |
||
438 | } |
||
439 | |||
440 | $this->addRequirement( |
||
441 | function_exists('json_encode'), |
||
442 | 'json_encode() must be available', |
||
443 | 'Install and enable the <strong>JSON</strong> extension.' |
||
444 | ); |
||
445 | |||
446 | $this->addRequirement( |
||
447 | function_exists('session_start'), |
||
448 | 'session_start() must be available', |
||
449 | 'Install and enable the <strong>session</strong> extension.' |
||
450 | ); |
||
451 | |||
452 | $this->addRequirement( |
||
453 | function_exists('ctype_alpha'), |
||
454 | 'ctype_alpha() must be available', |
||
455 | 'Install and enable the <strong>ctype</strong> extension.' |
||
456 | ); |
||
457 | |||
458 | $this->addRequirement( |
||
459 | function_exists('token_get_all'), |
||
460 | 'token_get_all() must be available', |
||
461 | 'Install and enable the <strong>Tokenizer</strong> extension.' |
||
462 | ); |
||
463 | |||
464 | $this->addRequirement( |
||
465 | function_exists('simplexml_import_dom'), |
||
466 | 'simplexml_import_dom() must be available', |
||
467 | 'Install and enable the <strong>SimpleXML</strong> extension.' |
||
468 | ); |
||
469 | |||
470 | if (function_exists('apc_store') && ini_get('apc.enabled')) { |
||
471 | $this->addRequirement( |
||
472 | version_compare(phpversion('apc'), '3.0.17', '>='), |
||
473 | 'APC version must be at least 3.0.17', |
||
474 | 'Upgrade your <strong>APC</strong> extension (3.0.17+).' |
||
475 | ); |
||
476 | } |
||
477 | |||
478 | $this->addPhpIniRequirement('detect_unicode', false); |
||
479 | |||
480 | ob_start(); |
||
481 | phpinfo(); |
||
482 | $phpinfo = ob_get_contents(); |
||
483 | ob_end_clean(); |
||
484 | |||
485 | // the phpinfo check is necessary when Suhosin is compiled into PHP |
||
486 | if (extension_loaded('suhosin') || false !== strpos($phpinfo, 'Suhosin')) { |
||
487 | $this->addPhpIniRequirement( |
||
488 | 'suhosin.executor.include.whitelist', |
||
489 | create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'), |
||
490 | false, |
||
491 | 'suhosin.executor.include.whitelist must be configured correctly in php.ini', |
||
492 | 'Add "<strong>phar</strong>" to <strong>suhosin.executor.include.whitelist</strong> in php.ini<a href="#phpini">*</a>.' |
||
493 | ); |
||
494 | } |
||
495 | |||
496 | if (extension_loaded('xdebug')) { |
||
497 | $this->addPhpIniRequirement( |
||
498 | 'xdebug.show_exception_trace', false, true |
||
499 | ); |
||
500 | |||
501 | $this->addPhpIniRequirement( |
||
502 | 'xdebug.scream', false, true |
||
503 | ); |
||
504 | } |
||
505 | |||
506 | $pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null; |
||
507 | |||
508 | $this->addRequirement( |
||
509 | null !== $pcreVersion && $pcreVersion > 8.0, |
||
510 | sprintf('PCRE extension must be available and at least 8.0 (%s installed)', $pcreVersion ? $pcreVersion : 'not'), |
||
511 | 'Upgrade your <strong>PCRE</strong> extension (8.0+).' |
||
512 | ); |
||
513 | |||
514 | /* optional recommendations follow */ |
||
515 | |||
516 | $this->addRecommendation( |
||
517 | file_get_contents(__FILE__) === file_get_contents(__DIR__.'/../vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/skeleton/app/SymfonyRequirements.php'), |
||
518 | 'Requirements file should be up-to-date', |
||
519 | 'Your requirements file is outdated. Run composer install and re-check your configuration.' |
||
520 | ); |
||
521 | |||
522 | $this->addRecommendation( |
||
523 | version_compare($installedPhpVersion, '5.3.4', '>='), |
||
524 | 'You should use at least PHP 5.3.4 due to PHP bug #52083 in earlier versions', |
||
525 | '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.' |
||
526 | ); |
||
527 | |||
528 | $this->addRecommendation( |
||
529 | version_compare($installedPhpVersion, '5.3.8', '>='), |
||
530 | 'When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156', |
||
531 | 'Install PHP 5.3.8 or newer if your project uses annotations.' |
||
532 | ); |
||
533 | |||
534 | $this->addRecommendation( |
||
535 | version_compare($installedPhpVersion, '5.4.0', '!='), |
||
536 | 'You should not use PHP 5.4.0 due to the PHP bug #61453', |
||
537 | '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.' |
||
538 | ); |
||
539 | |||
540 | $this->addRecommendation( |
||
541 | class_exists('DomDocument'), |
||
542 | 'PHP-XML module should be installed', |
||
543 | 'Install and enable the <strong>PHP-XML</strong> module.' |
||
544 | ); |
||
545 | |||
546 | $this->addRecommendation( |
||
547 | function_exists('mb_strlen'), |
||
548 | 'mb_strlen() should be available', |
||
549 | 'Install and enable the <strong>mbstring</strong> extension.' |
||
550 | ); |
||
551 | |||
552 | $this->addRecommendation( |
||
553 | function_exists('iconv'), |
||
554 | 'iconv() should be available', |
||
555 | 'Install and enable the <strong>iconv</strong> extension.' |
||
556 | ); |
||
557 | |||
558 | $this->addRecommendation( |
||
559 | function_exists('utf8_decode'), |
||
560 | 'utf8_decode() should be available', |
||
561 | 'Install and enable the <strong>XML</strong> extension.' |
||
562 | ); |
||
563 | |||
564 | if (!defined('PHP_WINDOWS_VERSION_BUILD')) { |
||
565 | $this->addRecommendation( |
||
566 | function_exists('posix_isatty'), |
||
567 | 'posix_isatty() should be available', |
||
568 | 'Install and enable the <strong>php_posix</strong> extension (used to colorize the CLI output).' |
||
569 | ); |
||
570 | } |
||
571 | |||
572 | $this->addRecommendation( |
||
573 | class_exists('Locale'), |
||
574 | 'intl extension should be available', |
||
575 | 'Install and enable the <strong>intl</strong> extension (used for validators).' |
||
576 | ); |
||
577 | |||
578 | if (class_exists('Collator')) { |
||
579 | $this->addRecommendation( |
||
580 | null !== new Collator('fr_FR'), |
||
581 | 'intl extension should be correctly configured', |
||
582 | 'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.' |
||
583 | ); |
||
584 | } |
||
585 | |||
586 | if (class_exists('Locale')) { |
||
587 | if (defined('INTL_ICU_VERSION')) { |
||
588 | $version = INTL_ICU_VERSION; |
||
589 | } else { |
||
590 | $reflector = new ReflectionExtension('intl'); |
||
591 | |||
592 | ob_start(); |
||
593 | $reflector->info(); |
||
594 | $output = strip_tags(ob_get_clean()); |
||
595 | |||
596 | preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches); |
||
597 | $version = $matches[1]; |
||
598 | } |
||
599 | |||
600 | $this->addRecommendation( |
||
601 | version_compare($version, '4.0', '>='), |
||
602 | 'intl ICU version should be at least 4+', |
||
603 | 'Upgrade your <strong>intl</strong> extension with a newer ICU version (4+).' |
||
604 | ); |
||
605 | } |
||
606 | |||
607 | $accelerator = |
||
608 | (function_exists('apc_store') && ini_get('apc.enabled')) |
||
609 | || |
||
610 | function_exists('eaccelerator_put') && ini_get('eaccelerator.enable') |
||
611 | || |
||
612 | function_exists('xcache_set') |
||
613 | ; |
||
614 | |||
615 | $this->addRecommendation( |
||
616 | $accelerator, |
||
617 | 'a PHP accelerator should be installed', |
||
618 | 'Install and enable a <strong>PHP accelerator</strong> like APC (highly recommended).' |
||
619 | ); |
||
620 | |||
621 | $this->addPhpIniRecommendation('short_open_tag', false); |
||
622 | |||
623 | $this->addPhpIniRecommendation('magic_quotes_gpc', false, true); |
||
624 | |||
625 | $this->addPhpIniRecommendation('register_globals', false, true); |
||
626 | |||
627 | $this->addPhpIniRecommendation('session.auto_start', false); |
||
628 | |||
629 | $this->addRecommendation( |
||
630 | class_exists('PDO'), |
||
631 | 'PDO should be installed', |
||
632 | 'Install <strong>PDO</strong> (mandatory for Doctrine).' |
||
633 | ); |
||
634 | |||
635 | if (class_exists('PDO')) { |
||
636 | $drivers = PDO::getAvailableDrivers(); |
||
637 | $this->addRecommendation( |
||
638 | count($drivers), |
||
639 | sprintf('PDO should have some drivers installed (currently available: %s)', count($drivers) ? implode(', ', $drivers) : 'none'), |
||
640 | 'Install <strong>PDO drivers</strong> (mandatory for Doctrine).' |
||
641 | ); |
||
645 |