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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
<?php
/**
* Extract class variables and their documentation from phpcode
* @author Ulf Wendel <ulf@redsys.de>
* @version 0.2
*/
class PhpdocVariableParser extends PhpdocModuleParser {
/**
* Array with default values of a variable
*
* @var array $emptyVariable
* @see variables, analyseVariableParagraph()
*/
var $emptyVariable = array(
"name" => "",
"undoc" => true
);
/**
* Array of tags that are allowed in front of the var keyword
* @var array $variableTags
* @see analyseVariableParagraph()
*/
var $variableTags = array(
"access" => true,
"abstract" => true,
"static" => true,
"final" => true,
"see" => true,
"link" => true,
"var" => true,
"version" => true,
"since" => true,
"deprecated" => true,
"deprec" => true,
"brother" => true,
"sister" => true,
"exclude" => true,
"magic" => true,
"todo" => true
);
/**
* Analyses a variable doc comment
* @param array Hash returned by getPhpdocParagraph()
* @return array
*/
function analyseVariable($para) {
$variable = $this->emptyVariable;
$variable["name"] = $para["name"];
if (""!=$para["doc"]) {
$variable = $this->analyseTags($this->getTags($para["doc"]), $variable, $this->variableTags);
list($msg, $variable) = $this->checkParserErrors($variable, "variable");
if (""!=$msg)
$this->warn->addDocWarning($this->currentFile, "variable", $variable["name"], $msg, "mismatch");
list($variable["sdesc"], $variable["desc"]) = $this->getDescription($para["doc"]);
$variable["undoc"] = false;
}
list($type, $value, $raw_value) = $this->getVariableTypeAndValue($para["value"], false);
$variable["type"] = $type;
$variable["value"] = $value;
$variable = $this->checkVarDocs($variable);
return $variable;
} // end func analyseVariables
/**
* Compares the @var tag informations with the analyse of the source code.
*
* @param array $variable
* @return array $variable
*/
function checkVarDocs($variable) {
if (!isset($variable["var"]))
return $variable;
if ("unknown"!=$variable["type"] && $variable["var"]["type"] != $variable["type"]) {
$msg = sprintf("The documented class variable type does not match the type found. Update the tag to '@var %s [%s]'.",
$variable["type"],
$variable["name"]
);
$this->warn->addDocWarning($this->currentFile, "variable", $variable["name"], $msg, "mismatch");
}
if ($variable["var"]["name"] != $variable["name"]) {
$msg = sprintf("The documented class variable name does not match the name found. Update the tag to '@var %s [%s]'.",
$variable["type"],
$variable["name"]
);
$this->warn->addDocWarning($this->currentFile, "variable", $variable["name"], $msg, "mismatch");
}
unset($variable["var"]);
return $variable;
} // end func checkVarDocs
} // end class PhpdocVariableParser
?>
|