cvs: php4 /pear/PHPDoc/analyser PhpdocAnalyser.php PhpdocClassAnalyser.php PhpdocModuleAnalyser.php /pear/PHPDoc/parser PhpdocParserTags.php

From: Date: Sun, 03 Dec 2000 16:47:15 +0000
Subject: cvs: php4 /pear/PHPDoc/analyser PhpdocAnalyser.php PhpdocClassAnalyser.php PhpdocModuleAnalyser.php /pear/PHPDoc/parser PhpdocParserTags.php
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2882@lists.php.net to get a copy of this message
uw Sun Dec 3 08:47:15 2000 EDT Modified files: /php4/pear/PHPDoc/analyser PhpdocAnalyser.php PhpdocClassAnalyser.php PhpdocModuleAnalyser.php /php4/pear/PHPDoc/parser PhpdocParserTags.php Log: - fixed a @see bug and improved @see "@see element" now causes a warning. To referr to functions or variables within a class/module use "@see $variable" and "@see function()". Note the $ and the "()". If the referenced element is unknow, the reference will be dropped and a warning is generated. - added @version $Id: $ to some class doc comments This is an eays way to add a version tag to inline docs if you use a CVS. - added spaces around operators

Index: php4/pear/PHPDoc/analyser/PhpdocAnalyser.php diff -u php4/pear/PHPDoc/analyser/PhpdocAnalyser.php:1.3 php4/pear/PHPDoc/analyser/PhpdocAnalyser.php:1.4 --- php4/pear/PHPDoc/analyser/PhpdocAnalyser.php:1.3 Sat Dec 2 16:37:58 2000 +++ php4/pear/PHPDoc/analyser/PhpdocAnalyser.php Sun Dec 3 08:47:14 2000 @@ -8,16 +8,28 @@ * - inherit elements * - inherit information * +* @version $Id: PhpdocAnalyser.php,v 1.4 2000/12/03 16:47:14 uw Exp $ */ class PhpdocAnalyser extends PhpdocObject { /** * Flag indicating that getModule/getClass was called. + * * @var boolean */ var $flag_get = false; - + /** + * List of all elements of a certain class/module. + * + * The array is used to look up @see references + * + * @var array Format: elementlist[ eltype ][ elname ] = true + * @see buildElementlist() + */ + var $elementlist = array(); + + /** * Adds a suffix to the number like 1st, 2nd and 3th * * @param integer $nr number to format @@ -141,6 +153,34 @@ function findUndocumented() { ; } // end func findUndocumented + + /** + * Checks all @see references in the given classes/modulegroup. + * + * @abstract + */ + function checkSee() { + ; + } // end func checkSee + + /** + * Checks @see references in the given elementlist. + * + * @abstract + */ + function checkSeeElement() { + ; + } // end func checkSeeElement + + /** + * Build a list of all elemente (functions, variables,...) of a certain class/module + * + * @abstract + * @see $elementlist + */ + function buildElementlist() { + ; + } // end func buildElementlist /** * Compares the argument list generated from the function head with the @param tags found. @@ -189,7 +229,7 @@ } return array(); - + } // compare the informations from the parser with the @param tags Index: php4/pear/PHPDoc/analyser/PhpdocClassAnalyser.php diff -u php4/pear/PHPDoc/analyser/PhpdocClassAnalyser.php:1.2 php4/pear/PHPDoc/analyser/PhpdocClassAnalyser.php:1.3 --- php4/pear/PHPDoc/analyser/PhpdocClassAnalyser.php:1.2 Sat Dec 2 16:37:58 2000 +++ php4/pear/PHPDoc/analyser/PhpdocClassAnalyser.php Sun Dec 3 08:47:14 2000 @@ -1,6 +1,8 @@ <?php /** * Analyses a class. +* +* @version $Id: PhpdocClassAnalyser.php,v 1.3 2000/12/03 16:47:14 uw Exp $ */ class PhpdocClassAnalyser extends PhpdocAnalyser { @@ -106,6 +108,7 @@ $this->updateAccessReturn(); $this->updateBrothersSisters(); + $this->checkSee(); $this->classlist = array(); @@ -443,5 +446,98 @@ } // end func updateAccessElements + function checkSee() { + + reset($this->classes); + while (list($classname, $class) = each($this->classes)) { + + $this->buildElementlist($classname); + + if (isset($class["functions"])) + $this->checkSeeElements($class["functions"], $classname, "functions"); + + if (isset($class["variables"])) + $this->checkSeeElements($class["variables"], $classname, "variables"); + + if (isset($class["consts"])) + $this->checkSeeElements($class["consts"], $classname, "consts"); + + if (isset($class["uses"])) + $this->checkSeeElements($class["uses"], $classname, "uses"); + + } + + } // end func checkSee + + /** + * Checks @see references in the given element array (functions, variables...) + * + * References to variables and functions within the same class get checked. + * It the references element does not exist, the reference gets deleted and + * a doc warning gets generated. + * + * @param array List of functions, variables,... + * @param string Name of the class that contains the given elements. + * @param string Elementtype: functions, variables, consts, uses. + */ + function checkSeeElements($elements, $classname, $eltype) { + + reset($elements); + while (list($elname, $element) = each($elements)) { + + if (isset($element["see"])) { + + if (isset($element["see"]["var"])) { + + reset($element["see"]["var"]); + while (list($k, $variable) = each($element["see"]["var"])) + if (!isset($this->elementlist["variables"][$variable["name"]])) { + $this->warn->addDocWarning($this->classes[$classname]["filename"], "variables", $elname, "@see referrs to the variable '" . $variable["name"] . "' which is not defined in the class. Entry gets ignored.", "mismatch"); + unset($this->classes[$classname][$eltype][$elname]["see"]["var"][$k]); + } + + } + + if (isset($element["see"]["function"])) { + + reset($element["see"]["function"]); + while (list($k, $function) = each($element["see"]["function"])) + if (!isset($this->elementlist["functions"][substr($function["name"], 0, -2)])) { + $this->warn->addDocWarning($this->classes[$classname]["filename"], "functions", $elname, "@see referrs to the function '" . $function["name"] . "' which is not defined in the class. Entry gets ignored.", "mismatch"); + unset($this->classes[$classname][$eltype][$elname]["see"]["function"][$k]); + } + + } + + } + + } + + } // end func checkSeeElement + + /** + * Builds an array with all elements of a class and saves it to $this->elementlist. + * + * @param string Name of the class to scan. + */ + function buildElementlist($classname) { + + $elements = array(); + $fields = array("functions", "variables", "consts", "uses"); + + reset($fields); + while (list($k, $field) = each($fields)) + if (isset($this->classes[$classname][$field])) { + + reset($this->classes[$classname][$field]); + while (list($element, ) = each($this->classes[$classname][$field])) + $elements[$field][$element] = true; + + } + + $this->elementlist = $elements; + + } // end func buildElementlist + } // end class PhpdocClassAnalyser ?> Index: php4/pear/PHPDoc/analyser/PhpdocModuleAnalyser.php diff -u php4/pear/PHPDoc/analyser/PhpdocModuleAnalyser.php:1.2 php4/pear/PHPDoc/analyser/PhpdocModuleAnalyser.php:1.3 --- php4/pear/PHPDoc/analyser/PhpdocModuleAnalyser.php:1.2 Sat Dec 2 16:37:58 2000 +++ php4/pear/PHPDoc/analyser/PhpdocModuleAnalyser.php Sun Dec 3 08:47:14 2000 @@ -1,6 +1,8 @@ <?php /** * Analyses a modulegroup. +* +* @version $Id: PhpdocModuleAnalyser.php,v 1.3 2000/12/03 16:47:14 uw Exp $ */ class PhpdocModuleAnalyser extends PhpdocAnalyser { @@ -47,7 +49,8 @@ $this->updateAccessReturn(); $this->updateBrothersSisters(); - + $this->checkSee(); + $this->checkFunctionArgs(); $this->findUndocumented(); @@ -67,7 +70,7 @@ $this->flag_get = true; } - if (list($modulename, $group)=each($this->modulelist)) { + if (list($modulename, $group) = each($this->modulelist)) { $module = $this->modulegroup[$group][$modulename]; unset($this->modulegroup[$group][$modulename]); @@ -84,20 +87,20 @@ function findUndocumented() { reset($this->modulegroup); - while (list($group, $modules)=each($this->modulegroup)) { + while (list($group, $modules) = each($this->modulegroup)) { reset($modules); - while (list($name, $module)=each($modules)) { + while (list($name, $module) = each($modules)) { reset($this->undocumentedFields); - while (list($index, $eltype)=each($this->undocumentedFields)) { + while (list($index, $eltype) = each($this->undocumentedFields)) { if (!isset($module[$index])) continue; $file = $module["filename"]; reset($module[$index]); - while (list($elname, $data)=each($module[$index])) + while (list($elname, $data) = each($module[$index])) if (isset($data["undoc"]) && $data["undoc"]) $this->warn->addDocWarning($file, $eltype, $elname, "Undocumented element.", "missing"); } @@ -111,17 +114,17 @@ function checkFunctionArgs() { reset($this->modulegroup); - while (list($group, $modules)=each($this->modulegroup)) { + while (list($group, $modules) = each($this->modulegroup)) { reset($modules); - while (list($name, $module)=each($modules)) { + while (list($name, $module) = each($modules)) { if (!isset($module["functions"])) continue; $file = $module["filename"]; reset($module["functions"]); - while (list($fname, $function)=each($module["functions"])) { + while (list($fname, $function) = each($module["functions"])) { $this->modulegroup[$group][$name]["functions"][$fname]["params"] = $this->checkArgDocs($function["args"], $function["params"], $fname, $file, false); unset($this->modulegroup[$group][$name]["functions"][$fname]["args"]); } @@ -141,10 +144,10 @@ $this->modulelist = array(); reset($this->modulegroup); - while (list($group, $modules)=each($this->modulegroup)) { + while (list($group, $modules) = each($this->modulegroup)) { reset($modules); - while (list($modulename, $data)=each($modules)) + while (list($modulename, $data) = each($modules)) $this->modulelist[$modulename] = $group; } @@ -155,7 +158,7 @@ function updateBrothersSisters() { reset($this->modulelist); - while (list($modulename, $group)=each($this->modulelist)) { + while (list($modulename, $group) = each($this->modulelist)) { $this->updateBrotherSisterElements($group, $modulename, "functions"); $this->updateBrotherSisterElements($group, $modulename, "variables"); } @@ -168,11 +171,11 @@ return false; reset($this->modulegroup[$group][$modulename][$type]); - while (list($elementname, $data)=each($this->modulegroup[$group][$modulename][$type])) { + while (list($elementname, $data) = each($this->modulegroup[$group][$modulename][$type])) { if (isset($data["brother"])) { - $name = ( "functions" == $type ) ? substr($data["brother"], 0, -2) : substr($data["brother"], 1); + $name = ("functions" == $type) ? substr($data["brother"], 0, -2) : substr($data["brother"], 1); $name = strtolower($name); if (!isset($this->modulegroup[$group][$modulename][$type][$name])) { @@ -196,7 +199,7 @@ function updateAccessReturn() { reset($this->modulelist); - while (list($modulename, $group)=each($this->modulelist)) { + while (list($modulename, $group) = each($this->modulelist)) { if (!isset($this->modulegroup[$group][$modulename]["access"])) $this->modulegroup[$group][$modulename]["access"] = "private"; @@ -215,7 +218,7 @@ return false; reset($this->modulegroup[$group][$modulename][$type]); - while (list($elementname, $data)=each($this->modulegroup[$group][$modulename][$type])) { + while (list($elementname, $data) = each($this->modulegroup[$group][$modulename][$type])) { if (!isset($data["access"])) $this->modulegroup[$group][$modulename][$type][$elementname]["access"] = "private"; @@ -233,7 +236,7 @@ return false; reset($this->modulegroup[$group][$modulename][$type]); - while (list($elementname, $data)=each($this->modulegroup[$group][$modulename][$type])) { + while (list($elementname, $data) = each($this->modulegroup[$group][$modulename][$type])) { if (!isset($data["access"])) $this->modulegroup[$group][$modulename][$type][$elementname]["access"] = "private"; @@ -241,6 +244,104 @@ } } // end func updateAccessElements + + function checkSee() { + + reset($this->modulegroup); + while (list($group, $modules) = each($this->modulegroup)) { + + while (list($modulename, $module) = each($modules)) { + + $this->buildElementlist($group, $modulename); + + if (isset($module["functions"])) + $this->checkSeeElements($module["functions"], $group, $modulename, "functions"); + + if (isset($module["variables"])) + $this->checkSeeElements($module["variables"], $group, $modulename, "variables"); + + if (isset($module["consts"])) + $this->checkSeeElements($module["consts"], $group, $modulename, "consts"); + + if (isset($module["uses"])) + $this->checkSeeElements($module["uses"], $group, $modulename, "uses"); + + } + + } + + } // end func checkSee + + /** + * Checks @see references in the given element array (functions, variables...) + * + * References to variables and functions within the same module get checked. + * It the references element does not exist, the reference gets deleted and + * a doc warning gets generated. + * + * @param array List of functions, variables,... + * @param string Name of the module that contains the given elements. + * @param string Elementtype: functions, variables, consts, uses. + */ + function checkSeeElements($elements, $modulegroup, $modulename, $eltype) { + + reset($elements); + while (list($elname, $element) = each($elements)) { + + if (isset($element["see"])) { + + if (isset($element["see"]["var"])) { + + reset($element["see"]["var"]); + while (list($k, $variable) = each($element["see"]["var"])) + if (!isset($this->elementlist["variables"][$variable["name"]])) { + $this->warn->addDocWarning($this->modulegroup[$modulegroup][$modulename]["filename"], "variables", $elname, "@see referrs to the variable '" . $variable["name"] . "' which is not defined in the class. Entry gets ignored.", "mismatch"); + unset($this->modulegroup[$modulegroup][$modulename][$eltype][$elname]["see"]["var"][$k]); + } + + } + + if (isset($element["see"]["function"])) { + + reset($element["see"]["function"]); + while (list($k, $function) = each($element["see"]["function"])) + if (!isset($this->elementlist["functions"][substr($function["name"], 0, -2)])) { + $this->warn->addDocWarning($this->modulegroup[$modulename]["filename"], "functions", $elname, "@see referrs to the function '" . $function["name"] . "' which is not defined in the class. Entry gets ignored.", "mismatch"); + unset($this->modulegroup[$modulegroup][$modulename][$eltype][$elname]["see"]["function"][$k]); + } + + } + + } + + } + + } // end func checkSeeElement + + /** + * Builds an array with all elements of a class and saves it to $this->elementlist. + * + * @param string Name of the modulegroup that contains the module. + * @param string Name of the module to scan. + */ + function buildElementlist($modulegroup, $modulename) { + + $elements = array(); + $fields = array("functions", "variables", "consts", "uses"); + + reset($fields); + while (list($k, $field) = each($fields)) + if (isset($this->modulegroup[$modulegroup][$modulename][$field])) { + + reset($this->modulegroup[$modulegroup][$modulename][$field]); + while (list($element, ) = each($this->modulegroup[$modulegroup][$modulename][$field])) + $elements[$field][$element] = true; + + } + + $this->elementlist = $elements; + + } // end func buildElementlist } // end class PhpdocModuleAnalyser ?> Index: php4/pear/PHPDoc/parser/PhpdocParserTags.php diff -u php4/pear/PHPDoc/parser/PhpdocParserTags.php:1.1 php4/pear/PHPDoc/parser/PhpdocParserTags.php:1.2 --- php4/pear/PHPDoc/parser/PhpdocParserTags.php:1.1 Sun Oct 8 03:03:19 2000 +++ php4/pear/PHPDoc/parser/PhpdocParserTags.php Sun Dec 3 08:47:15 2000 @@ -1,8 +1,14 @@ <?php +/** +* Functions used to parse PHPDoc Tags. +* +* @version $Id: PhpdocParserTags.php,v 1.2 2000/12/03 16:47:15 uw Exp $ +*/ class PhpdocParserTags extends PhpdocParserRegExp { - /** + /** * Extract the value from the given tags and copy the data to the $data array if its an allowed tag + * * @param array $tags array of tags returned by getTags * @param array $data array where the allowed tags and their values are copied to * @param array $allowed array of allowed (recognized) tags @@ -18,7 +24,7 @@ } reset($tags); - while (list($k, $tag)=each($tags)) { + while (list($k, $tag) = each($tags)) { $tagname = substr( strtolower($tag["tag"]), 1 ); if (!isset($allowed[$tagname])) { @@ -46,9 +52,9 @@ } - if (""==$tag["value"]) { + if ("" == $tag["value"]) { - $tag["msg"] = "Description is missing, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "Description is missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; $data[$tagname] = $tag["value"]; @@ -70,7 +76,7 @@ } - if (""!=$tag["value"]) { + if ("" != $tag["value"]) { $tag["msg"] = "Description gets ignored, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; $data["syntaxerror"][] = $tag; @@ -92,31 +98,37 @@ if (preg_match($this->TAGS[$tagname], $tag["value"], $regs)) { - if ("object"==$regs[1]) { + if ("object" == $regs[1]) { $type = "object "; - if ( ""==$regs[2] ) { - $type.= "[unknown]"; - $tag["msg"] = "Objectname is missing, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + if ( "" == $regs[2] ) { + + $type .= "[unknown]"; + $tag["msg"] = "Objectname is missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; + } else { - $type.= $regs[2]; + + $type .= $regs[2]; + } } else { + $type = $regs[1]; + } $data[$tagname] = array ( "type" => $type, "name" => $regs[3] ); - if ("return"==$tagname && ""!=$regs[4]) + if ("return" == $tagname && "" != $regs[4]) $data[$tagname]["desc"] = $regs[4]; } else { - $tag["msg"] = "General syntax error, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } @@ -125,25 +137,33 @@ case "global": if (preg_match($this->TAGS["global"], $tag["value"], $regs)) { + + if ("" == $regs[3]) { - if (""==$regs[3]) { - $tag["msg"] = "Variablename ist missing, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "Variablename ist missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; + } - if ("object"==$regs[1]) { + if ("object" == $regs[1]) { $type = "object "; - if ( ""==$regs[2] ) { - $type.= "[unknown]"; - $tag["msg"] = "Objectname is missing, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + if ( "" == $regs[2] ) { + + $type .= "[unknown]"; + $tag["msg"] = "Objectname is missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; + } else { - $type.= $regs[2]; + + $type .= $regs[2]; + } } else { + $type = $regs[1]; + } if ("" == $regs[4]) { @@ -161,7 +181,7 @@ } else { - $tag["msg"] = "General syntax error, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } @@ -173,22 +193,28 @@ if (preg_match($this->TAGS["var"], $tag["value"], $regs)) { - if ("object"==$regs[1]) { + if ("object" == $regs[1]) { $type = "object "; - if ( ""==$regs[2] ) { - $type.= "[unknown]"; - $tag["msg"] = "Objectname is missing, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + if ("" == $regs[2]) { + + $type .= "[unknown]"; + $tag["msg"] = "Objectname is missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; + } else { - $type.= $regs[2]; + + $type .= $regs[2]; + } } else { + $type = $regs[1]; + } - if (""==$regs[4]) { + if ("" == $regs[4]) { $data["params"][] = array ( "type" => $type, "name" => $regs[3] @@ -212,57 +238,64 @@ case "see": - if (""!=$tag["value"]) { + if ("" != $tag["value"]) { $error = ""; $references = explode(",", $tag["value"] ); reset($references); - while (list($k, $reference)=each($references)) { + while (list($k, $reference) = each($references)) { if (preg_match($this->TAGS["see_var"], $reference, $regs)) { list($msg, $entry) = $this->analyseSeeTagRegs($regs); - $error.=$msg; - if (count($entry)>0) + $error .= $msg; + if (count($entry) > 0) $data["see"]["var"][] = $entry; } else if (preg_match($this->TAGS["see_function"], $reference, $regs)) { list($msg, $entry) = $this->analyseSeeTagRegs($regs); - $error.=$msg; - if (count($entry)>0) + $error .= $msg; + if (count($entry) > 0) $data["see"]["function"][] = $entry; } else if (preg_match($this->TAGS["see_moduleclass"], $reference, $regs)) { - + $name = $regs[1]; - + if (substr($name, 0, $this->C_COMPLEX["module_separator_len"]) == $this->C_BASE["module_separator"]) { $name = substr($name, $this->C_COMPLEX["module_separator_len"]); - if (""==$name) { + if ("" == $name) { - $error.= "Element name is missing: '$regs[0]'. Reference gets ignored"; + $error .= "Element name is missing: '$regs[0]'. Reference gets ignored"; continue; } else { - $error.= "Element name starts with moduleseparator, module name forgotten '$regs[0]'?"; + $error .= "Element name starts with moduleseparator, module name forgotten '$regs[0]'?"; + continue; } + } else if (!strstr($name, $this->C_BASE["module_separator"])) { + + $error .= "Use function() to referr to functions and $var to referr to variables - don't know what '$name' referrs to."; + continue; + } + $data["see"]["moduleclass"][] = $name; } else { - $error.= "Unknown syntax '$reference'"; + $error .= "Unknown syntax '$reference'"; } } - if (""!=$error) { + if ( "" != $error) { $tag["msg"] = sprintf("Could not understand all references. %s. Syntax: '%s' (function), '%s' (variable), '%s' (module or class).", $error, @@ -276,7 +309,7 @@ } else { - $tag["msg"] = "General syntax error, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } @@ -288,19 +321,23 @@ $desc = trim($regs[2]); if ("" == $desc) { + $data["link"][] = array( "url" => $regs[1] ); + } else { + $data["link"][] = array( "url" => $regs[1], "desc" => trim($regs[2]) ); + } } else { - $tag["msg"] = "General syntax error, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } @@ -308,17 +345,18 @@ case "throws": - if (""!=$tag["value"]) { + if ("" != $tag["value"]) { $exceptions = explode(",", $tag["value"]); reset($exceptions); - while (list($k, $exception)=each($exceptions)) + while (list($k, $exception) = each($exceptions)) $data["throws"][] = trim($exception); } else { - $tag["msg"] = "General syntax error, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; + } break; @@ -330,8 +368,8 @@ } else { - $tag["msg"] = (""==$tag["value"]) ? "General syntax error," : "Access modifier unknown,"; - $tag["msg"].= " '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = ("" == $tag["value"]) ? "General syntax error," : "Access modifier unknown,"; + $tag["msg"].= " '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } @@ -349,13 +387,13 @@ } - if (""!=$tag["value"]) { + if ("" != $tag["value"]) { $data["deprec"] = $tag["value"]; } else { - $tag["msg"] = "Description is missing, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "Description is missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } @@ -372,7 +410,7 @@ } - if (""!=$tag["value"]) { + if ("" != $tag["value"]) { if (preg_match($this->TAGS["brother"], $tag["value"], $regs)) { @@ -380,15 +418,14 @@ } else { - $tag["msg"] = "Can't find a function name nor a variable name, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "Can't find a function name nor a variable name, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } - } else { - $data["msg"] = "General syntax error, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $data["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } @@ -405,7 +442,7 @@ } - if (""!=$tag["value"]) { + if ("" != $tag["value"]) { if (preg_match($this->TAGS["module"], $tag["value"], $regs)) { @@ -413,14 +450,14 @@ } else { - $tag["msg"] = "Illegal label used, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "Illegal label used, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } } else { - $tag["msg"] = "General syntax error, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } @@ -437,7 +474,7 @@ } - if (""!=$tag["value"]) { + if ("" != $tag["value"]) { if (preg_match($this->TAGS["const"], $tag["value"], $regs)) { @@ -448,14 +485,14 @@ } else { - $tag["msg"] = "General syntax error, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } } else { - $tag["msg"] = "General syntax error, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } @@ -463,11 +500,11 @@ case "author": - if (""!=$tag["value"]) { + if ("" != $tag["value"]) { $authors = explode(",", $tag["value"]); reset($authors); - while (list($k, $author)=each($authors)) { + while (list($k, $author) = each($authors)) { if (preg_match($this->TAGS["author"], $author, $regs)) { @@ -492,7 +529,7 @@ } else { - $tag["msg"] = "General syntax error, syntax: ".$this->PHPDOC_TAGS["@$tagname"]."'."; + $tag["msg"] = "General syntax error, syntax: " . $this->PHPDOC_TAGS["@$tagname"] . "'."; $data["syntaxerror"][] = $tag; } @@ -513,6 +550,7 @@ /** * Helperfunction to analyse @see tags + * * @param array Array return by preg_match() * @return array $see[0] = error, $see[1] = data * @see analyseTags() @@ -520,13 +558,13 @@ function analyseSeeTagRegs($regs) { $error = ""; - $group = $regs[1]; - $name = $regs[2]; + $group = trim($regs[1]); + $name = trim($regs[2]); if (substr($name, 0, $this->C_COMPLEX["module_separator_len"]) == $this->C_BASE["module_separator"]) { $name = substr($name, $this->C_COMPLEX["module_separator_len"]); - if (""==$name) { + if ("" == $name) { $error = "Element name is missing '$regs[0]'. Reference gets ignored"; return array($error, array()); @@ -539,10 +577,10 @@ } - if (""!=$group && $this->C_BASE["module_separator"]!=$group) { + if ("" != $group && $this->C_BASE["module_separator"] != $group) { $group = substr($group, 0, $this->C_COMPLEX["module_separator_len_neg"]); - if (""==$group) { + if ("" == $group) { $error = "Groupname missing '$regs[0]'."; $data = array( "name" => $name ); @@ -567,6 +605,7 @@ /** * Extracts PHPDoc tags from a PHPDoc doc comment. + * * @param string Doc comment. * @return array List of tags ordered by their appearance containing the * tag name and it's (unparsed) value. @@ -576,21 +615,23 @@ $positions = $this->getTagPos($phpdoc); - if (0==count($positions)) + if (0 == count($positions)) return array(); reset($positions); - list($k, $data)=each($positions); + list($k, $data) = each($positions); $lastpos = $data["pos"]; $lasttag = $data["tag"]; + + while (list($k, $data) = each($positions)) { - while (list($k, $data)=each($positions)) { - $line = substr($phpdoc, $lastpos, ($data["pos"]-$lastpos)); + $line = substr($phpdoc, $lastpos, ($data["pos"] - $lastpos)); $value = trim(substr($line, strlen($lasttag))); $tags[] = array ("tag" => $lasttag, "value" => $value ); $lastpos = $data["pos"]; $lasttag = $data["tag"]; + } $line = substr($phpdoc, $lastpos); @@ -602,24 +643,29 @@ /** * Find the position of the next phpdoc tag. + * * @param string $phpdoc * @param int $offset * @return array $t 0 => tag, 1 => offset * @access private * @see findTags() */ - function getTagPos($phpdoc, $offset=0) { + function getTagPos($phpdoc, $offset = 0) { $positions = array(); preg_match_all($this->TAGS["all"], $phpdoc, $regs, PREG_SET_ORDER); + reset($regs); - while (list($k, $data)=each($regs)) { + while (list($k, $data) = each($regs)) { + $pos = strpos($phpdoc, $data[0], $offset); - if ($pos>0 || $data[0]==substr($phpdoc, 0, strlen($data[0])) ) { + + if ($pos > 0 || $data[0] == substr($phpdoc, 0, strlen($data[0])) ) { $positions[] = array ("pos" => $pos, "tag" => $data[0]); $offset = $pos+1; } + } return $positions; @@ -643,10 +689,10 @@ // tags with an incorrect syntax if (isset($data["syntaxerror"])) { - $msg.= "PHPDoc found ".count($data["syntaxerror"])." syntax error(s) in the tag list. "; + $msg.= "PHPDoc found " . count($data["syntaxerror"]) . " syntax error(s) in the tag list. "; reset($data["syntaxerror"]); - while (list($k, $error)=each($data["syntaxerror"])) + while (list($k, $error) = each($data["syntaxerror"])) $msg.= sprintf("Tag: '%s %s' - %s.", $error["tag"], $error["value"], $error["msg"]); unset($data["syntaxerror"]); @@ -656,26 +702,26 @@ // tags that are not allowed in this context if (isset($data["notallowed"])) { - $msg.= count($data["notallowed"])." tag[s] were used that are not allowed in $mode doc comments: "; + $msg .= count($data["notallowed"]) . " tag[s] were used that are not allowed in $mode doc comments: "; reset($data["notallowed"]); - while (list($tagname, $v)=each($data["notallowed"])) - $msg.= "$tagname, "; + while (list($tagname, $v) = each($data["notallowed"])) + $msg .= "$tagname, "; - $msg = substr($msg, 0, -2)."."; + $msg = substr($msg, 0, -2) . "."; unset($data["notallowed"]); } // unknown tags if (isset($data["unknown"])) { - $msg.= "PHPDoc found ".count($data["unknown"])." tag[s] that are unknown: "; + $msg .= "PHPDoc found " . count($data["unknown"]) . " tag[s] that are unknown: "; reset($data["unknown"]); - while (list($k, $error)=each($data["unknown"])) + while (list($k, $error) = each($data["unknown"])) $msg.= sprintf("%s, ", $error["tag"]); - $msg = substr($msg, 0, -2)."."; + $msg = substr($msg, 0, -2) . "."; unset($data["unknown"]); }
« previous php.cvs (#2882) next »