Source for file Coverage.php
Documentation is available at Coverage.php
require_once 'QA/Peardoc/Coverage/ClassList.php';
require_once 'QA/Peardoc/Coverage/MethodList.php';
<!-- missing entities -->
* Simple peardoc coverage analysis.
* Compares the classes and methods in PEAR packages
* with the PEAR documentation, trying to find
* out which packages aren't documented at all,
* where documentation of parts is lacking or
* which packages are fully documented.
* $packagename has "_" replaced with "-"
* package.$category.$packagename
* package.$category.$shortpackagename
* package.$category.$packagename.$methodname
* package.html.html-template-it.show
* package.html.html-template-it.show.desc
* package.html.html-template-it.show.parameter
* package.html.html-template-it.show.throws
* package.$category.$packagename.$classname.$methodname
* package.html.html-quickform.html-quickform.addelement
* package.$category.$packagename.constructor
* package.gtk2.entrydialog.constructor
* package.$category.$packagename.$classname.$classname
* package.datetime.calendar.calendar-day.calendar-day
* - differentiate between stable and unstable packages
* @package QA_Peardoc_Coverage
* @author Christian Weiske <cweiske@php.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Coverage.php,v 1.11 2007/07/18 18:52:44 cweiske Exp $
* @link http://pear.php.net/package/QA_Peardoc_Coverage
* Special category associations.
public static $arCategoryAssociation = array (
'benchmark' => 'benchmarking',
'calendar' => 'datetime',
'games_chess' => 'structures',
'genealogy_gedcom' => 'fileformats',
'i18nv2' => 'internationalization',
'math_numbers' => 'numbers',
'message' => 'encryption',
'pager_sliding' => 'html',
'phpdocumentor' => 'php',
'search_mnogosearch' => 'tools',
'spreadsheet_excel_writer' => 'fileformats',
'sql_parser' => 'database',
'translation' => 'internationalization',
'translation2' => 'internationalization',
'xml_rpc' => 'webservices',
'xml_rpc2' => 'webservices',
* List with package category name => Doc category name
* Doc category assignments may be arrays of strings.
public static $arCategoryDocNames = array (
'archive' => 'fileformats',
'auth' => 'authentication',
'config' => 'configuration',
'contact' => 'fileformats',
'file' => array ('fileformats', 'filesystem'),
'i18n' => 'internationalization',
'liveuser' => 'authentication',
'services' => 'webservices',
* Lowercase package names that should be ignored.
public static $arIgnoredPackages = array (
* Creates a new coverage checker instance.
* @param string $strManualPath Full path to the manual.xml file
* of the pear documentation.
* @param string $strPearDir Path of PEAR CVS checkout directory
public function __construct($strManualPath, $strPearDir)
$this->strManualPath = $strManualPath;
$this->strPearDir = $strPearDir;
}//public function __construct($strManualPath, $strPearDir)
* Generates the coverage analysis
* @return array Documentation coverage array. Pass it to a render() method.
* This is an array with doc statistics.
* special value: documentation id
* special value: path to package cvs
* value: array, NULL if no doc
foreach (self ::getPackageList ($this->strPearDir)
as $strPackageDir => $strPackage
$arCategories = self ::getCategory ($strPackage);
foreach ($arCategories as $strCategory) {
$arDoc[$strCategory][$strPackage] = array (
'*package*' => $strPackageDir
$arDoc[$strCategory][$strPackage] =
foreach ($arDoc as &$arPackages) {
$arDoc['*date*'] = time();
}//public function generateCoverage()
* Renders the coverage analysis into a viewable format.
* @param array $arCoverage Coverage analysis array from generateCoverage()
* @param string $strRenderer Classname of the renderer
* @param array $arOptions Array of options if needed
* @return string Viewable coverage analysis.
$strRenderer = 'QA_Peardoc_Coverage_Renderer_SimplePackageList',
require_once str_replace('_', '/', $strRenderer) . '.php';
array ($strRenderer, 'render'),
}//public static function renderCoverage(..)
* Loads the given xml file into a DOM document.
* @param string $strManualPath Full path to the manual.xml file
* of the pear documentation.
* @return boolean true if all is ok.
throw new Exception ('Manual file does not exist: ' . $strManualPath);
$this->doc = new DOMDocument ();
$this->doc->resolveExternals = true;
$this->doc->substituteEntities = true;
if ($this->doc->load ($strManualPath)) {
$this->xpath = new DOMXPath ($this->doc);
throw new Exception ('manual XML could not be loaded.');
}//protected function loadXmlDocument($strManualPath)
* Returns a list of packages and their paths
* @param string $strPearDir PEAR CVS directory
* @return array Array with package dir as key and package name as value
if (substr($strPearDir, -1 ) != '/') {
glob($strPearDir . '*/packag{e,e2}.xml', GLOB_BRACE )
$strPackageDir = substr($strPackageFilePath, 0 , strrpos($strPackageFilePath, '/'));
$arPackages[$strPackageDir] = basename($strPackageDir);
}//public static function getPackageList($strPearDir)
* Returns the category name for the package.
* @param string $strPackage Package name (e.g. Gtk2_EntryDialog)
* @return string Array with category names (lowercase)
if (isset (self ::$arCategoryAssociation[$strPackage])) {
$strCategory = self ::$arCategoryAssociation[$strPackage];
$nPos = strpos ($strPackage, '_');
$strCategory = $strPackage;
$strCategory = substr($strPackage, 0 , $nPos);
if (isset (self ::$arCategoryDocNames[$strCategory])) {
$arCategories = self ::$arCategoryDocNames[$strCategory];
$arCategories = array ($strCategory);
if (!is_array ($arCategories)) {
$arCategories = array ($arCategories);
$arCategories = array_map('strtolower', $arCategories);
}//public static function getCategory($strPackage)
* Returns the ID of the XML node of the package
* in the pear documentation.
* @param string $strPackage Package name
* @param string $strCategory Category name, gotten from self::getCategory()
* @return string The id, or NULL if not found -> not documented.
$strId = 'package.' . $strCategory . '.' . $strPackageIdName;
$strId2 = 'package.' . $strCategory . '.' . $strPackageIdName2;
$strId3 = 'core.' . $strCategory . '.' . $strPackageIdName;
//echo $strId . "|" . $strId2 . "|" . $strId3 . "\n";
}//public function getPackageDocId($strPackage)
* Checks if an id exists in the manual
* @param string $strId XML id="" to check
* @return boolean True if it exists, false if not
return $this->doc->getElementById ($strId) != null;
}//public function existsId($strId)
* Creates the documentation coverage for the given package.
* A class is considered documented if either an ID
* /baseid + "." + classname/ exists, or the classname
* is surrounded by <classname> tags at least once.
* Functions/methds are considered as documented if
* they are mentioned inside a <function> tag or
* an id like /baseid + "." + classname + "." + functionname/
* @param string $strPackage Package name
* @param string $strCategory Category (lowercase)
* @param string $strBaseId Base documentation id attribute
* @param string $strPackageDir Package directory
* @return array Array with doc coverage information
'*package*' => $strPackageDir
$baseElement = $this->doc->getElementById ($strBaseId);
//find <classname> elements
foreach ($baseElement->getElementsByTagName ('classname') as $classElement) {
$arDocClasses[$classElement->nodeValue ] = true;
QA_Peardoc_Coverage_ClassList ::getFileList ($strPackageDir)
foreach ($arClasses as $strClassName => $arMethods) {
if ($strClassName[0 ] == '*') {
//Check if class is documented
if ($strClassName == $strPackage) {
$strClassDocId2 = $strBaseId;
if (!isset ($arDocClasses[$strClassName]) && !$this->existsId($strClassDocId)) {
//class is not documented
$arDoc[$strClassName] = null;
foreach ($baseElement->getElementsByTagName ('function') as $funcElement) {
$arDocMethods[$funcElement->nodeValue ] = true;
$arDoc[$strClassName] = array ();
foreach ($arMethods as $strMethod => $bDocBlock) {
if ($strMethod == $strClassName || $strMethod == '__construct') {
if (isset ($arDocMethods[$strMethod])) {
//first check if the method is in a <function> tag
$arDoc[$strClassName][$strMethod] = true;
//then check if the method has its own section
if (!$this->existsId($strMethodDocId)) {
if ($strClassDocId2 !== null && $this->existsId($strMethodDocId2)) {
$arDoc[$strClassName][$strMethod] = true;
$arDoc[$strClassName][$strMethod] = false;
$arDoc[$strClassName][$strMethod] = true;
}//public function getPackageCoverage($strPackage, $strCategory, $strBaseId, $strPackageDir)
}//class QA_Peardoc_Coverage
Documentation generated on Mon, 11 Mar 2019 15:10:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|