Back to index

php5  5.3.10
search_underscores.php
Go to the documentation of this file.
00001 #! /usr/local/bin/php -n
00002 <?php
00003 
00004 /*
00005    +----------------------------------------------------------------------+
00006    | PHP Version 5                                                        |
00007    +----------------------------------------------------------------------+
00008    | Copyright (c) 1997-2006 The PHP Group                                |
00009    +----------------------------------------------------------------------+
00010    | This source file is subject to version 3.01 of the PHP license,      |
00011    | that is bundled with this package in the file LICENSE, and is        |
00012    | available through the world-wide-web at the following url:           |
00013    | http://www.php.net/license/3_01.txt                                  |
00014    | If you did not receive a copy of the PHP license and are unable to   |
00015    | obtain it through the world-wide-web, please send a note to          |
00016    | license@php.net so we can mail you a copy immediately.               |
00017    +----------------------------------------------------------------------+
00018    | Authors: Marcus Boerger <helly@php.net>                              |
00019    +----------------------------------------------------------------------+
00020  */
00021 
00022 /* This script lists extension-, class- and method names that contain any
00023    underscores. It omits magic names (e.g. anything that starts with two
00024    underscores but no more).
00025  */
00026 
00027 $cnt_modules = 0;
00028 $cnt_classes = 0;
00029 $cnt_methods = 0;
00030 $err = 0;
00031 
00032 $classes = array_merge(get_declared_classes(), get_declared_interfaces());
00033 
00034 $extensions = array();
00035 
00036 foreach(get_loaded_extensions() as $ext) {
00037        $cnt_modules++;
00038        if (strpos($ext, "_") !== false) {
00039               $err++;
00040               $extensions[$ext] = array();
00041        }
00042 }
00043 
00044 $cnt_classes = count($classes);
00045 
00046 foreach($classes as $c) {
00047        if (strpos($c, "_") !== false) {
00048               $err++;
00049               $ref = new ReflectionClass($c);
00050               if (!($ext = $ref->getExtensionName())) {;
00051                      $ext = $ref->isInternal() ? "<internal>" : "<user>";
00052               }
00053               if (!array_key_exists($ext, $extensions)) {
00054                      $extensions[$ext] = array();
00055               }
00056               $extensions[$ext][$c] = array();
00057               foreach(get_class_methods($c) as $method) {
00058                      $cnt_methods++;
00059                      if (strpos(substr($method, substr($method, 0, 2) != "__"  ? 0 : 2), "_") !== false) {
00060                             $err++;
00061                             $extensions[$ext][$c][] = $method;
00062                      }
00063               }
00064        }
00065        else
00066        {
00067               $cnt_methods += count(get_class_methods($c));
00068        }
00069 }
00070 
00071 $cnt = $cnt_modules + $cnt_classes + $cnt_methods;
00072 
00073 printf("\n");
00074 printf("Modules: %5d\n", $cnt_modules);
00075 printf("Classes: %5d\n", $cnt_classes);
00076 printf("Methods: %5d\n", $cnt_methods);
00077 printf("\n");
00078 printf("Names:   %5d\n", $cnt);
00079 printf("Errors:  %5d (%.1f%%)\n", $err, round($err * 100 / $cnt, 1));
00080 printf("\n");
00081 
00082 ksort($extensions);
00083 foreach($extensions as $ext => &$classes) {
00084        echo "Extension: $ext\n";
00085        ksort($classes);
00086        foreach($classes as $classname => &$methods) {
00087               echo "  Class: $classname\n";
00088               ksort($methods);
00089               foreach($methods as $method) {
00090                      echo "    Method: $method\n";
00091               }
00092        }
00093 }
00094 
00095 printf("\n");
00096 
00097 ?>