PHPCSAliases.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * PHPCompatibility, an external standard for PHP_CodeSniffer.
  4. *
  5. * PHPCS cross-version compatibility helper.
  6. *
  7. * @package PHPCompatibility
  8. * @copyright 2012-2019 PHPCompatibility Contributors
  9. * @license https://opensource.org/licenses/LGPL-3.0 LGPL3
  10. * @link https://github.com/PHPCompatibility/PHPCompatibility
  11. *
  12. * @since 8.0.0
  13. */
  14. /*
  15. * Alias a number of PHPCS 3.x classes to their PHPCS 2.x equivalents.
  16. *
  17. * This file is auto-loaded by PHPCS 3.x before any sniffs are loaded
  18. * through the PHPCS 3.x `<autoload>` ruleset directive.
  19. *
  20. * {@internal The PHPCS file have been reorganized in PHPCS 3.x, quite
  21. * a few "old" classes have been split and spread out over several "new"
  22. * classes. In other words, this will only work for a limited number
  23. * of classes.}
  24. *
  25. * {@internal The `class_exists` wrappers are needed to play nice with other
  26. * external PHPCS standards creating cross-version compatibility in the same
  27. * manner.}
  28. */
  29. if (defined('PHPCOMPATIBILITY_PHPCS_ALIASES_SET') === false) {
  30. if (interface_exists('\PHP_CodeSniffer_Sniff') === false) {
  31. class_alias('PHP_CodeSniffer\Sniffs\Sniff', '\PHP_CodeSniffer_Sniff');
  32. }
  33. if (class_exists('\PHP_CodeSniffer_File') === false) {
  34. class_alias('PHP_CodeSniffer\Files\File', '\PHP_CodeSniffer_File');
  35. }
  36. if (class_exists('\PHP_CodeSniffer_Tokens') === false) {
  37. class_alias('PHP_CodeSniffer\Util\Tokens', '\PHP_CodeSniffer_Tokens');
  38. }
  39. if (class_exists('\PHP_CodeSniffer_Exception') === false) {
  40. class_alias('PHP_CodeSniffer\Exceptions\RuntimeException', '\PHP_CodeSniffer_Exception');
  41. }
  42. if (class_exists('\PHP_CodeSniffer_Standards_AbstractScopeSniff') === false) {
  43. class_alias('PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Standards_AbstractScopeSniff');
  44. }
  45. if (class_exists('\Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff') === false) {
  46. class_alias('PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff', '\Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff');
  47. }
  48. define('PHPCOMPATIBILITY_PHPCS_ALIASES_SET', true);
  49. /*
  50. * Register an autoloader.
  51. *
  52. * {@internal When `installed_paths` is set via the ruleset, this autoloader
  53. * is needed to run the sniffs.
  54. * Upstream issue: {@link https://github.com/squizlabs/PHP_CodeSniffer/issues/1591} }
  55. *
  56. * @since 8.0.0
  57. */
  58. spl_autoload_register(function ($class) {
  59. // Only try & load our own classes.
  60. if (stripos($class, 'PHPCompatibility') !== 0) {
  61. return;
  62. }
  63. $file = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php';
  64. if (file_exists($file)) {
  65. include_once $file;
  66. }
  67. });
  68. }