validate-deprecation-aliases.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/php -q
  2. <?php
  3. $options = [
  4. __DIR__ . '/../vendor/autoload.php',
  5. __DIR__ . '/vendor/autoload.php',
  6. ];
  7. if (!empty($_SERVER['PWD'])) {
  8. array_unshift($options, $_SERVER['PWD'] . '/vendor/autoload.php');
  9. }
  10. foreach ($options as $file) {
  11. if (file_exists($file)) {
  12. define('COMPOSER_INSTALL', $file);
  13. break;
  14. }
  15. }
  16. require COMPOSER_INSTALL;
  17. $path = dirname(__DIR__) . DS . 'src' . DS;
  18. $di = new RecursiveDirectoryIterator($path, (RecursiveDirectoryIterator::SKIP_DOTS));
  19. /** @var \SplFileInfo[] $iterator */
  20. $iterator = new RecursiveIteratorIterator($di);
  21. $issues = [];
  22. $code = 0;
  23. foreach ($iterator as $file) {
  24. if (pathinfo($file, PATHINFO_EXTENSION) !== 'php') {
  25. continue;
  26. }
  27. if (pathinfo($file, PATHINFO_FILENAME) === 'functions') {
  28. continue;
  29. }
  30. if (strpos($file->getRealPath(), '/TestSuite/')) {
  31. continue;
  32. }
  33. $content = file_get_contents($file);
  34. if (!strpos($content, 'class_alias(')) {
  35. continue;
  36. }
  37. preg_match('#class_alias\(\s*\'([^\']+)\',#', $content, $matches);
  38. if (!$matches) {
  39. var_dump($content);
  40. var_dump($file->getPath());
  41. exit(1);
  42. }
  43. echo $matches[1] . PHP_EOL;
  44. $filePath = str_replace('\\', '/', $matches[1]);
  45. $filePath = str_replace('Cake/', $path, $filePath);
  46. $filePath .= '.php';
  47. if (!file_exists($filePath)) {
  48. throw new RuntimeException('Cannot find path for ' . $matches[1]);
  49. }
  50. $newFileContent = file_get_contents($filePath);
  51. if (strpos($newFileContent, 'class_exists(') === false && strpos($newFileContent, 'class_alias(') === false ) {
  52. $oldPath = str_replace($path, '', $file->getRealPath());
  53. $newPath = str_replace($path, '', $filePath);
  54. echo "\033[31m" . ' * Missing class_exists() or class_alias() on new file for ' . $oldPath . ' => ' . $newPath . "\033[0m" . PHP_EOL;
  55. $code = 1;
  56. } else {
  57. echo ' * OK' . PHP_EOL;
  58. }
  59. }
  60. exit($code);