search_underscores.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #! /usr/local/bin/php -n
  2. <?php
  3. /*
  4. +----------------------------------------------------------------------+
  5. | PHP Version 5 |
  6. +----------------------------------------------------------------------+
  7. | Copyright (c) 1997-2006 The PHP Group |
  8. +----------------------------------------------------------------------+
  9. | This source file is subject to version 3.01 of the PHP license, |
  10. | that is bundled with this package in the file LICENSE, and is |
  11. | available through the world-wide-web at the following url: |
  12. | http://www.php.net/license/3_01.txt |
  13. | If you did not receive a copy of the PHP license and are unable to |
  14. | obtain it through the world-wide-web, please send a note to |
  15. | license@php.net so we can mail you a copy immediately. |
  16. +----------------------------------------------------------------------+
  17. | Authors: Marcus Boerger <helly@php.net> |
  18. +----------------------------------------------------------------------+
  19. */
  20. /* This script lists extension-, class- and method names that contain any
  21. underscores. It omits magic names (e.g. anything that starts with two
  22. underscores but no more).
  23. */
  24. $cnt_modules = 0;
  25. $cnt_classes = 0;
  26. $cnt_methods = 0;
  27. $err = 0;
  28. $classes = array_merge(get_declared_classes(), get_declared_interfaces());
  29. $extensions = array();
  30. foreach(get_loaded_extensions() as $ext) {
  31. $cnt_modules++;
  32. if (strpos($ext, "_") !== false) {
  33. $err++;
  34. $extensions[$ext] = array();
  35. }
  36. }
  37. $cnt_classes = count($classes);
  38. foreach($classes as $c) {
  39. if (strpos($c, "_") !== false) {
  40. $err++;
  41. $ref = new ReflectionClass($c);
  42. if (!($ext = $ref->getExtensionName())) {;
  43. $ext = $ref->isInternal() ? "<internal>" : "<user>";
  44. }
  45. if (!array_key_exists($ext, $extensions)) {
  46. $extensions[$ext] = array();
  47. }
  48. $extensions[$ext][$c] = array();
  49. foreach(get_class_methods($c) as $method) {
  50. $cnt_methods++;
  51. if (strpos(substr($method, substr($method, 0, 2) != "__" ? 0 : 2), "_") !== false) {
  52. $err++;
  53. $extensions[$ext][$c][] = $method;
  54. }
  55. }
  56. }
  57. else
  58. {
  59. $cnt_methods += count(get_class_methods($c));
  60. }
  61. }
  62. $cnt = $cnt_modules + $cnt_classes + $cnt_methods;
  63. printf("\n");
  64. printf("Modules: %5d\n", $cnt_modules);
  65. printf("Classes: %5d\n", $cnt_classes);
  66. printf("Methods: %5d\n", $cnt_methods);
  67. printf("\n");
  68. printf("Names: %5d\n", $cnt);
  69. printf("Errors: %5d (%.1f%%)\n", $err, round($err * 100 / $cnt, 1));
  70. printf("\n");
  71. ksort($extensions);
  72. foreach($extensions as $ext => &$classes) {
  73. echo "Extension: $ext\n";
  74. ksort($classes);
  75. foreach($classes as $classname => &$methods) {
  76. echo " Class: $classname\n";
  77. ksort($methods);
  78. foreach($methods as $method) {
  79. echo " Method: $method\n";
  80. }
  81. }
  82. }
  83. printf("\n");
  84. ?>