File: checkdoc.php

package info (click to toggle)
php-doc 20100521-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 59,992 kB
  • ctags: 4,085
  • sloc: xml: 796,833; php: 21,338; cpp: 500; sh: 117; makefile: 58; awk: 28
file content (173 lines) | stat: -rw-r--r-- 5,779 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/php -q
<?php
/*
  +----------------------------------------------------------------------+
  | PHP Version 4                                                        |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2010 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors:    Stig Bakken <ssb@php.net> (originally in Perl)           |
  |             Gabor Hojtsy <goba@php.net>                              |
  +----------------------------------------------------------------------+
*/

if ($argc > 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>

Check documented functions in phpdoc

  Usage:
  <?php echo $argv[0];?> [missing]

  By providing the optional "missing" parameter,
  only a list of undocumented functions is listed,
  otherwise a full status report is printed.
  
  This program depends on ../funclist.txt as the
  list of functions compiled from the PHP source.
<?php
  exit;
}

// CONFIG SECTION
$docdir  = "../en/functions";
$funclist = "../funclist.txt";

/*********************************************************************/
/* Nothing to modify below this line                                 */
/*********************************************************************/

// Documented functions list
$func_documented = array();

// Functions in PHP (from funclist.txt)
$func_in_php = array();

// Longest function name for display
$longest = 0;

/*********************************************************************/
/* Here starts the functions part                                    */
/*********************************************************************/

// Checks a diretory of phpdoc XML files
function check_dir($dir, &$functions)
{
    // Collect files and diretcories in these arrays
    $directories = array();
    $files = array();

    // Open and traverse the directory
    $handle = @opendir($dir);
    while ($file = @readdir($handle)) {

      // Collect XML files
      if (strstr($file, ".xml")) {
        $files[] = $file;
      }

    }
    @closedir($handle);

    // Sort and check files
    sort($files);
    foreach ($files as $file) {
      check_file($dir, $file, $functions);
    }

} // check_dir() function end

function check_file ($dirname, $filename, &$functions)
{
    // Read in file contents
    $contents = preg_replace("/[\r\n]/", "", join("", file($dirname.$filename)));
    
    // Find all functions defined in this file
    preg_match_all("!id\s*=\s*([\"'])(function|class)\.([^\\1]+)\\1!U", $contents, $ids_found);

    // No ids found in file
    if (count($ids_found[3]) == 0) { return; }
    
    // Put functions into function list
    foreach ($ids_found[3] as $id) {
        $functions[str_replace("-", "_", $id)] = $filename;
    }
    ksort($functions);

} // check_file() function end
  
// Parse funclist.txt file for function names
function parse_funclist($funclist, &$longest, &$functions)
{
    // Read in file, initialize longest
    $file_lines = file($funclist);
    
    // Go through all lines, and find function names
    foreach ($file_lines as $line) {
        $line = trim($line);
        $length = strlen($line);
        // Not a comment, and contains a function name
        if ($line[0] != "#" && $length > 0) {
            $functions[] = $line;
            if ($length > $longest) { $longest = $length; }
        }
    }
    sort($functions);
    $functions = array_unique($functions);

} // parse_funclist() function end

/*********************************************************************/
/* Here starts the program                                           */
/*********************************************************************/

// Start with searching header
echo "Searching in $docdir for XML files...\n";
    
// Check the requested directory
check_dir("$docdir/", $func_documented);

// Process $funclist for PHP functions
parse_funclist($funclist, $longest, $func_in_php);
   
if ($argv[1] == "missing") {
    $undocumented = array_diff($func_in_php, array_keys($func_documented));
    echo "Functions in PHP source but not in documentation:\n\n";
    foreach ($undocumented as $func) {
      echo $func . "\n";
    }
} else {
    printf("%-{$longest}s    %s\n", "FUNCTION NAME", "DOCUMENTED IN");
    printf("%'-70s\n", '');
    foreach ($func_in_php as $function) {
        printf("%-{$longest}s    %s\n", $function, $func_documented[$function]);
    }
    $n_functions = count($func_in_php);
    $n_documented = count($func_documented);
    $percent_done = intval(($n_documented * 100) / $n_functions);

    printf("\n%d of %d functions documented (%d%% done, %d%% remaining).\n",
       $n_documented, $n_functions, $percent_done, 100-$percent_done);
}

echo "Possible documentation errors coming:\n\n";
$is_error = FALSE;
foreach ($func_documented as $func => $file) {
    if (!in_array($func, $func_in_php)) {
        echo "  $func in $file but not in $funclist\n";
        $is_error = TRUE;
    }
}
if (!$is_error) { echo "No documented but not implemented functions found.\n"; }

echo "Done!";

?>