php-cs-fixer 3.9 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. error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
  13. set_error_handler(static function ($severity, $message, $file, $line) {
  14. if ($severity & error_reporting()) {
  15. throw new ErrorException($message, 0, $severity, $file, $line);
  16. }
  17. });
  18. // check environment requirements
  19. (function () {
  20. if (defined('HHVM_VERSION_ID')) {
  21. fwrite(STDERR, "HHVM is not supported.\n");
  22. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  23. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  24. } else {
  25. exit(1);
  26. }
  27. } elseif (!defined('PHP_VERSION_ID')) { // PHP_VERSION_ID is available as of PHP 5.2.7
  28. fwrite(STDERR, 'PHP version no supported, please update. Current PHP version: '.PHP_VERSION.".\n");
  29. exit(1);
  30. } elseif (\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. } elseif (
  35. \PHP_VERSION_ID < 70400
  36. || \PHP_VERSION_ID >= 80200
  37. ) {
  38. fwrite(STDERR, "PHP needs to be a minimum version of PHP 7.4.0 and maximum version of PHP 8.1.*.\n");
  39. fwrite(STDERR, 'Current PHP version: '.PHP_VERSION.".\n");
  40. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  41. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  42. } else {
  43. fwrite(STDERR, "To ignore this requirement please set `PHP_CS_FIXER_IGNORE_ENV`.\n");
  44. fwrite(STDERR, "If you use PHP version higher than supported, you may experience code modified in a wrong way.\n");
  45. fwrite(STDERR, "Please report such cases at https://github.com/FriendsOfPHP/PHP-CS-Fixer .\n");
  46. exit(1);
  47. }
  48. }
  49. foreach (['json', 'tokenizer'] as $extension) {
  50. if (!extension_loaded($extension)) {
  51. fwrite(STDERR, sprintf("PHP extension ext-%s is missing from your system. Install or enable it.\n", $extension));
  52. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  53. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  54. } else {
  55. exit(1);
  56. }
  57. }
  58. }
  59. })();
  60. // load dependencies
  61. (function () {
  62. $require = true;
  63. if (class_exists('Phar')) {
  64. // Maybe this file is used as phar-stub? Let's try!
  65. try {
  66. Phar::mapPhar('php-cs-fixer.phar');
  67. require_once 'phar://php-cs-fixer.phar/vendor/autoload.php';
  68. $require = false;
  69. } catch (PharException $e) {
  70. }
  71. }
  72. if ($require) {
  73. // OK, it's not, let give Composer autoloader a try!
  74. $possibleFiles = [__DIR__.'/../../autoload.php', __DIR__.'/../autoload.php', __DIR__.'/vendor/autoload.php'];
  75. $file = null;
  76. foreach ($possibleFiles as $possibleFile) {
  77. if (file_exists($possibleFile)) {
  78. $file = $possibleFile;
  79. break;
  80. }
  81. }
  82. if (null === $file) {
  83. throw new RuntimeException('Unable to locate autoload.php file.');
  84. }
  85. require_once $file;
  86. }
  87. })();
  88. use Composer\XdebugHandler\XdebugHandler;
  89. use PhpCsFixer\Console\Application;
  90. // Restart if xdebug is loaded, unless the environment variable PHP_CS_FIXER_ALLOW_XDEBUG is set.
  91. $xdebug = new XdebugHandler('PHP_CS_FIXER');
  92. $xdebug->check();
  93. unset($xdebug);
  94. $application = new Application();
  95. $application->run();
  96. __HALT_COMPILER();