svn: /phpdoc/doc-base/trunk/scripts/ check-missing-docs.php

From: Date: Tue, 25 May 2010 22:19:43 +0000
Subject: svn: /phpdoc/doc-base/trunk/scripts/ check-missing-docs.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-6730@lists.php.net to get a copy of this message
philip Tue, 25 May 2010 22:19:43 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=299756 Log: - Rewrote to be more efficient :) (as suggested by David Tajchreber) - Added a few checks to remove several false positives (David) - Removed -v option, now uses PDO::sqlite instead of sqlite3, and a few more tweaks Changed paths: U phpdoc/doc-base/trunk/scripts/check-missing-docs.php Modified: phpdoc/doc-base/trunk/scripts/check-missing-docs.php =================================================================== --- phpdoc/doc-base/trunk/scripts/check-missing-docs.php 2010-05-25 21:54:21 UTC (rev 299755) +++ phpdoc/doc-base/trunk/scripts/check-missing-docs.php 2010-05-25 22:19:43 UTC (rev 299756) @@ -15,132 +15,124 @@ TODO - Deal with the above, hopefully fix - Deal with aliases (store them and/or find where/how they are stored, then use this info + - Skip intentionally undocumented stuff - Make the output more useful - Use some reflection? USAGE Pass in the following options: - d: required, is the index (sqlite3 db) created by running PhD - - v: optional, is not very useful, except it outputs stuff as the script runs - - Example: php check-missing-docs.php -d ./doc/phd_output/index.sqlite -v + - Example: php check-missing-docs.php -d ./doc/phd_output/index.sqlite */ -$options = getopt('d:v'); +$options = getopt('d:'); if (empty($options['d'])) { - echo "ERROR: Set -d to the path of your phd generated php doc index. And optionally pass in -v to output more stuff.\n"; + echo 'ERROR: Set -d foo where foo is the path to the PhD generated sqlite index.', PHP_EOL; exit; } $doc_db = trim($options['d']); if (!file_exists($doc_db)) { - echo "ERROR: Unable to find a file here (Path: $doc_db). Fail.\n"; + echo "ERROR: Unable to find a file here (Path: $doc_db). Fail.", PHP_EOL; exit; } -if (!extension_loaded('sqlite3')) { - echo "ERROR: This script requires the sqlite3 extension.\n"; +if (!extension_loaded('PDO')) { + echo 'ERROR: This script requires the PDO extension.', PHP_EOL; exit; +} else { + $drivers = PDO::getAvailableDrivers(); + if (!in_array('sqlite', $drivers)) { + echo 'ERROR: This script requires the PDO::sqlite driver. You have PDO but with the following drivers:', PHP_EOL; + print_r($drivers); + exit; + } } -define ('VERBOSE', (isset($options['v']) ? TRUE : FALSE)); +$documented = array('functions' => array(), 'methods' => array(), 'inis' => array(), 'classes' => array()); +$missing = $documented; -$undefined = array('functions' => array(), 'methods' => array(), 'inis' => array(), 'classes' => array()); -$counts_defined = array('functions' => 0, 'methods' => 0, 'inis' => 0, 'classes' => 0); +$pdo = new PDO('sqlite:' . $doc_db); +$r = $pdo->query('SELECT lower(sdesc) as sdec, lower(docbook_id) as docbook_id FROM ids'); +$table = $r->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE); -if (!$db = new SQLite3($doc_db)) { - echo "ERROR: Failed to utilize the powers of sqlite3.\n"; - exit; -} - // Functions -echo "Scanning functions\n"; $functions = get_defined_functions(); -foreach ($functions['internal'] as $function) { - $sql = "SELECT count(*) FROM ids WHERE LOWER(sdesc) = '" . strtolower($function) . "'"; - - if ($db->querySingle($sql) === 0) { - if (VERBOSE) { - echo $function . "\n"; - } - $undefined['functions'][] = $function; +foreach($functions['internal'] as $function) { + $function = strtolower($function); + if(isset($table[$function])) { + $documented['functions'][] = $function; } else { - ++$counts_defined['functions']; + $missing['functions'][] = $function; } } -// Classes and Methods -$classes = get_declared_classes(); -echo "Scanning classes and methods\n"; -foreach ($classes as $class) { - - // FIXME Not all classes have class.classname (why?) - $sql = "SELECT count(*) FROM ids WHERE LOWER(docbook_id) = 'class." . strtolower($class) . "'"; - - if ($db->querySingle($sql) === 0) { - if (VERBOSE) { - echo $class . "\n"; - } - $undefined['classes'][] = $class; +// Classes and Methods$class +foreach(get_declared_classes() as $class) { + // Classes + $class_l = strtolower($class); + if(isset($table[$class_l])) { + $documented['classes'][] = $class; } else { - ++$counts_defined['classes']; + $missing['classes'][] = $class; } - - $methods = get_class_methods($class); - - foreach ($methods as $method) { - $tmp = "$class::$method"; - $sql = "SELECT count(*) FROM ids WHERE LOWER(sdesc) = '" . strtolower($tmp) . "'"; + // Methods + foreach(get_class_methods($class) as $method) { + $method_l = strtolower($method); - if ($db->querySingle($sql) === 0) { + $rm = new ReflectionMethod($class, $method); + if(strtolower($rm->getDeclaringClass()->name) === $class_l) { - // Does this fully work? :) - $rm = new ReflectionMethod($class, $method); - $rp = $rm->getDeclaringClass(); - - // Skip if inherited - if ($rp->name !== $class) { - continue; + // Variations we end up with in the docs + // Others? + $j = strtolower($class_l . '::' . $method_l); + $o = strtolower($class_l . '->' . $method_l); + $v = strtolower($class_l . '->' . $method_l); + + if(isset($table[$j]) || isset($table[$v]) || isset($table[$o])) { + $documented['methods'][] = $method; + } else { + $missing['methods'][] = $class . '::' . $method; } - - if (VERBOSE) { - echo $tmp . "\n"; - } - $undefined['methods'][] = $tmp; - } else { - ++$counts_defined['methods']; } } } // Ini settings +$r = $pdo->query("SELECT lower(docbook_id) as docbook_id FROM ids WHERE docbook_id LIKE 'ini.%'"); +$table = $r->fetchAll(PDO::FETCH_COLUMN); + $inis = ini_get_all(); -echo "Scanning ini settings\n"; +echo 'Scanning ini settings', PHP_EOL; foreach ($inis as $ini => $ini_value) { - $ini_search = str_replace('_', '-', $ini); - $sql = "SELECT count(*) FROM ids WHERE LOWER(docbook_id) = 'ini." . strtolower($ini_search) . "'"; + $ini_search = 'ini.' . strtolower(str_replace('_', '-', $ini)); - if ($db->querySingle($sql) === 0) { - if (VERBOSE) { - echo $ini . "\n"; - } - $undefined['inis'][] = $ini; + if (in_array($ini_search, $table)) { + $documented['inis'][] = $ini; } else { - ++$counts_defined['inis']; + $missing['inis'][] = $ini; } } -echo "Statistics and information:\n"; -$counts_undefined = array( - 'methods' => count($undefined['methods']), - 'classes' => count($undefined['classes']), - 'inis' => count($undefined['inis']), - 'functions'=> count($undefined['functions']), +echo 'Statistics and information:', PHP_EOL; +$counts_missing = array( + 'methods' => count($missing['methods']), + 'classes' => count($missing['classes']), + 'inis' => count($missing['inis']), + 'functions'=> count($missing['functions']), ); +$counts_documented = array( + 'methods' => count($documented['methods']), + 'classes' => count($documented['classes']), + 'inis' => count($documented['inis']), + 'functions'=> count($documented['functions']), +); -echo "Undefined stuff\n"; -print_r($undefined); +echo "Missing documentation", PHP_EOL; +print_r($missing); -echo "Counts: Undefined stuff\n"; -print_r($counts_undefined); +echo "Counts: Missing documentation", PHP_EOL; +print_r($counts_missing); -echo "Counts: Defined stuff\n"; -print_r($counts_defined); +echo "Counts: Documented documentation", PHP_EOL; +print_r($counts_documented); +

« previous php.doc.cvs (#6730) next »