php-cs-fixer 3.6 KB

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