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
|
<?php
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| 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: Dave Barr <dave@php.net> |
+----------------------------------------------------------------------+
| Description: This file parses the manual and outputs all erroneous |
| <function> tag usage. |
+----------------------------------------------------------------------+
*/
/* path to phpdoc CVS checkout. if this file is in the scripts/ directory
* then the value below will be correct!
*/
$phpdoc = '../';
/* english! */
$lang = 'en';
/* initialize array and declare some language constructs */
$funcs = array( 'include' => true,
'include_once' => true,
'require' => true,
'require_once' => true,
'return' => true,
);
$total = 0;
/* recursive glob() with a callback function */
function globbetyglob($globber, $userfunc)
{
foreach (glob("$globber/*") as $file) {
if (is_dir($file)) {
globbetyglob($file, $userfunc);
}
else {
call_user_func($userfunc, $file);
}
}
}
/* make a function list from files in the functions/ directories */
function make_func_list($file)
{
global $funcs;
if (fnmatch("*/reference/*/functions/*.xml", $file)) {
$func = strtolower(str_replace(array('-', '.'), '_', substr(basename($file), 0, -4)));
$funcs[$func] = true;
}
}
/* find all <function> tags and report invalid functions */
function parse_file($file)
{
global $funcs, $phpdoc, $lang, $total;
/* ignore old functions directory */
if (fnmatch("$phpdoc/$lang/functions/*", $file))
return;
$f = file_get_contents($file);
if ($f != '') {
if (preg_match_all('|<function>(.*?)</function>|s', $f, $m)
&& is_array($m)
&& is_array($m[1]))
{
foreach ($m[1] as $func) {
$func = strtolower(str_replace(array('::', '->'), '_', trim($func)));
if ($funcs[$func] !== true) {
$total++;
$fileout = substr($file, strlen($phpdoc) + 1);
printf("%-60.60s <function>$func</function>\n", $fileout);
}
}
}
}
}
echo "Building a list of functions...\n";
globbetyglob("$phpdoc/$lang", 'make_func_list');
echo 'List complete. ' . count($funcs) . " functions.\n";
echo "Checking the manual for <function> tags that contain invalid functions...\n";
globbetyglob("$phpdoc/$lang", 'parse_file');
echo "Found $total occurrences.\n";
?>
|