File: check-underdocumented.php

package info (click to toggle)
php-doc 20241205~git.dfcbb86%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 70,956 kB
  • sloc: xml: 968,269; php: 23,883; javascript: 671; sh: 177; makefile: 37
file content (67 lines) | stat: -rw-r--r-- 1,641 bytes parent folder | download | duplicates (2)
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
<?php
error_reporting(-1);
/*
Introduction:
This script checks for undocumented stuff. Currently this means anything that
uses that 'warn.undocumented.func' entity, which are underdocumented methods/functions.

Note: This script will eventually be folded into docweb and be deprecated.  However, it's
nice/simple to run it without a docweb setup so works okay for now.

Help:
$ Run this script.
*/

// p: path to phpdoc/en
// h: help
$opts = getopt('p:h::');

if (!empty($opts['h']) || empty($opts['p'])) {
	usage();
}

$phpdoc_path = $opts['p'];

if (!is_dir($phpdoc_path)) {
	echo "Hey! This ($phpdoc_path) is not a directory!", PHP_EOL;
	usage();
	exit;
}

$undocumented = array();
$count        = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($phpdoc_path)) as $file) {

	$filepath = $file->getPathname();
	$filename = $file->getBasename();
	
	if (strpos($filepath, '.svn')) {
		continue;
	}

	if (!$file->isFile() || pathinfo($filepath, PATHINFO_EXTENSION) !== 'xml') {
		continue;
	}

	$fileid = str_replace($phpdoc_path, '', $filepath);
	$ext    = strtok($fileid, DIRECTORY_SEPARATOR);
	
	if (file_exists($phpdoc_path . $fileid)) {
		$contents = file_get_contents($phpdoc_path . $fileid);
		if (false !== strpos($contents, 'warn.undocumented.func')) {
			$undocumented[$ext][] = $fileid;
			++$count;
		}
		continue;
	}
}

echo 'List of underdocumented functions/methods', PHP_EOL;
print_r($undocumented);
echo "Number underdocumented: ", $count, PHP_EOL;

function usage() {
	echo PHP_EOL, 'USAGE:', PHP_EOL;
	echo 'php ', $_SERVER['SCRIPT_FILENAME'], ' -p /path/to/phpdoc/en/reference/', PHP_EOL;
	exit;
}