php-cs-fixer 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
  13. error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
  14. }
  15. if (defined('HHVM_VERSION_ID')) {
  16. fwrite(STDERR, "HHVM is not supported.\n");
  17. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  18. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  19. } else {
  20. exit(1);
  21. }
  22. } elseif (
  23. !defined('PHP_VERSION_ID')
  24. || \PHP_VERSION_ID === 80000
  25. || \PHP_VERSION_ID < 50600
  26. || \PHP_VERSION_ID >= 80100
  27. ) {
  28. fwrite(STDERR, "PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 8.0.*.\n");
  29. fwrite(STDERR, 'Current PHP version: '.PHP_VERSION.".\n");
  30. if (defined('PHP_VERSION_ID') && \PHP_VERSION_ID === 80000) {
  31. fwrite(STDERR, "PHP CS Fixer is not able run on PHP 8.0.0 due to bug in PHP tokenizer (https://bugs.php.net/bug.php?id=80462).\n");
  32. fwrite(STDERR, "Update PHP version to unblock execution.\n");
  33. exit(1);
  34. }
  35. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  36. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  37. } else {
  38. fwrite(STDERR, "To ignore this requirement please set `PHP_CS_FIXER_IGNORE_ENV`.\n");
  39. fwrite(STDERR, "If you use PHP version higher than supported, you may experience code modified in a wrong way.\n");
  40. fwrite(STDERR, "Please report such cases at https://github.com/FriendsOfPHP/PHP-CS-Fixer .\n");
  41. exit(1);
  42. }
  43. }
  44. foreach (['json', 'tokenizer'] as $extension) {
  45. if (!extension_loaded($extension)) {
  46. fwrite(STDERR, sprintf("PHP extension ext-%s is missing from your system. Install or enable it.\n", $extension));
  47. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  48. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  49. } else {
  50. exit(1);
  51. }
  52. }
  53. }
  54. unset($extension);
  55. set_error_handler(static function ($severity, $message, $file, $line) {
  56. if ($severity & error_reporting()) {
  57. throw new ErrorException($message, 0, $severity, $file, $line);
  58. }
  59. });
  60. $require = true;
  61. if (class_exists('Phar')) {
  62. // Maybe this file is used as phar-stub? Let's try!
  63. try {
  64. Phar::mapPhar('php-cs-fixer.phar');
  65. require_once 'phar://php-cs-fixer.phar/vendor/autoload.php';
  66. $require = false;
  67. } catch (PharException $e) {
  68. }
  69. }
  70. if ($require) {
  71. // OK, it's not, let give Composer autoloader a try!
  72. $possibleFiles = [__DIR__.'/../../autoload.php', __DIR__.'/../autoload.php', __DIR__.'/vendor/autoload.php'];
  73. $file = null;
  74. foreach ($possibleFiles as $possibleFile) {
  75. if (file_exists($possibleFile)) {
  76. $file = $possibleFile;
  77. break;
  78. }
  79. }
  80. if (null === $file) {
  81. throw new RuntimeException('Unable to locate autoload.php file.');
  82. }
  83. require_once $file;
  84. unset($possibleFiles, $possibleFile, $file);
  85. }
  86. unset($require);
  87. use Composer\XdebugHandler\XdebugHandler;
  88. use PhpCsFixer\Console\Application;
  89. // Restart if xdebug is loaded, unless the environment variable PHP_CS_FIXER_ALLOW_XDEBUG is set.
  90. $xdebug = new XdebugHandler('PHP_CS_FIXER', '--ansi');
  91. $xdebug->check();
  92. unset($xdebug);
  93. $application = new Application();
  94. $application->run();
  95. __HALT_COMPILER();