php-cs-fixer 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 (\PHP_VERSION_ID === 80000) {
  21. 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");
  22. fwrite(STDERR, "Update PHP version to unblock execution.\n");
  23. exit(1);
  24. }
  25. if (\PHP_VERSION_ID < 70400 || \PHP_VERSION_ID >= 80300) {
  26. fwrite(STDERR, "PHP needs to be a minimum version of PHP 7.4.0 and maximum version of PHP 8.2.*.\n");
  27. fwrite(STDERR, 'Current PHP version: '.PHP_VERSION.".\n");
  28. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  29. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  30. } else {
  31. fwrite(STDERR, "To ignore this requirement please set `PHP_CS_FIXER_IGNORE_ENV`.\n");
  32. fwrite(STDERR, "If you use PHP version higher than supported, you may experience code modified in a wrong way.\n");
  33. fwrite(STDERR, "Please report such cases at https://github.com/PHP-CS-Fixer/PHP-CS-Fixer .\n");
  34. exit(1);
  35. }
  36. }
  37. foreach (['json', 'tokenizer'] as $extension) {
  38. if (!extension_loaded($extension)) {
  39. fwrite(STDERR, sprintf("PHP extension ext-%s is missing from your system. Install or enable it.\n", $extension));
  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. exit(1);
  44. }
  45. }
  46. }
  47. })();
  48. // load dependencies
  49. (function () {
  50. $require = true;
  51. if (class_exists('Phar')) {
  52. // Maybe this file is used as phar-stub? Let's try!
  53. try {
  54. Phar::mapPhar('php-cs-fixer.phar');
  55. require_once 'phar://php-cs-fixer.phar/vendor/autoload.php';
  56. $require = false;
  57. } catch (PharException $e) {
  58. }
  59. }
  60. if ($require) {
  61. // OK, it's not, let give Composer autoloader a try!
  62. $possibleFiles = [__DIR__.'/../../autoload.php', __DIR__.'/../autoload.php', __DIR__.'/vendor/autoload.php'];
  63. $file = null;
  64. foreach ($possibleFiles as $possibleFile) {
  65. if (file_exists($possibleFile)) {
  66. $file = $possibleFile;
  67. break;
  68. }
  69. }
  70. if (null === $file) {
  71. throw new RuntimeException('Unable to locate autoload.php file.');
  72. }
  73. require_once $file;
  74. }
  75. })();
  76. use Composer\XdebugHandler\XdebugHandler;
  77. use PhpCsFixer\Console\Application;
  78. // Restart if xdebug is loaded, unless the environment variable PHP_CS_FIXER_ALLOW_XDEBUG is set.
  79. $xdebug = new XdebugHandler('PHP_CS_FIXER');
  80. $xdebug->check();
  81. unset($xdebug);
  82. $application = new Application();
  83. $application->run();
  84. __HALT_COMPILER();