home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 August / PCWorld_2001-08_cd.bin / Komunikace / phptriad / phptriadsetup2-11.exe / php / pear / PHPDoc / parser / PhpdocVariableParser.php < prev   
PHP Script  |  2001-02-18  |  5KB  |  129 lines

  1. <?php
  2. /**
  3. * Extract class variables and their documentation from phpcode
  4. *
  5. * @version  $Id: PhpdocVariableParser.php,v 1.4 2001/02/18 14:45:28 uw Exp $
  6. */
  7. class PhpdocVariableParser extends PhpdocModuleParser {
  8.  
  9.     /**
  10.     * Array with default values of a variable
  11.     * 
  12.     * @var    array        $emptyVariable
  13.     */
  14.     var $emptyVariable = array(
  15.                                 "name"  => "",
  16.                                 "undoc" => true
  17.                           );
  18.  
  19.     /**
  20.     * Array of tags that are allowed in front of the var keyword
  21.     *
  22.     * @var    array    $variableTags
  23.     * @see    analyseVariableParagraph()
  24.     */
  25.     var $variableTags = array(
  26.                                 "access"        => true,
  27.                                 "abstract"      => true,
  28.                                 "static"        => true,
  29.                                 "final"         => true,
  30.                                 
  31.                                 "see"           => true,
  32.                                 "link"          => true,
  33.                                 
  34.                                 "var"           => true,
  35.                                 
  36.                                 "version"       => true,
  37.                                 "since"         => true,
  38.                                 
  39.                                 "deprecated"    => true,
  40.                                 "deprec"        => true,
  41.                                 
  42.                                 "brother"       => true, 
  43.                                 "sister"        => true,
  44.                                 
  45.                                 "exclude"       => true,
  46.                                 "magic"         => true,
  47.                                 "todo"          => true
  48.                           );
  49.  
  50.     /**
  51.     * Analyses a variable doc comment
  52.     *
  53.     * @param    array    Hash returned by getPhpdocParagraph()
  54.     * @return   array 
  55.     */                                            
  56.   function analyseVariable($para) {
  57.         
  58.         $variable = $this->emptyVariable;
  59.         $variable["name"] = $para["name"];
  60.         
  61.         if ("" != $para["doc"]) {
  62.             
  63.             $variable = $this->analyseTags($this->getTags($para["doc"]), $variable, $this->variableTags);
  64.             
  65.             list($msg, $variable) = $this->checkParserErrors($variable, "variable");
  66.             if ("" != $msg)
  67.                 $this->warn->addDocWarning($this->currentFile, "variable", $variable["name"], $msg, "mismatch");
  68.                 
  69.             list($variable["sdesc"], $variable["desc"]) = $this->getDescription($para["doc"]);
  70.             
  71.             $variable["undoc"] = false;
  72.             
  73.         }
  74.         
  75.         list($type, $value, $raw_value) = $this->getVariableTypeAndValue($para["value"], false);
  76.         $variable["type"]     = $type;
  77.         
  78.         if ("unknown" != $value) 
  79.             $variable["value"] = $value;
  80.         
  81.         $variable = $this->checkVarDocs($variable);
  82.         
  83.         return $variable;
  84.     } // end func analyseVariables
  85.     
  86.     /**
  87.     * Compares the var tag informations with the analyse of the source code.
  88.     *
  89.     * @param    array   $variable
  90.     * @return   array   $variable
  91.     */
  92.     function checkVarDocs($variable) {
  93.         
  94.         if (!isset($variable["var"]))
  95.             return $variable;
  96.             
  97.         if ("unknown" != $variable["type"] && "mixed" != $variable["type"] && $variable["var"]["type"] != $variable["type"]) {
  98.             
  99.             $msg = sprintf("The documented class variable type does not match the type found. Update the tag to '@var %s [%s]%s'.",
  100.                             $variable["type"],
  101.                             $variable["name"],
  102.                             (isset($variable["var"]["desc"])) ? " " . $variable["var"]["desc"] : ""
  103.                         );
  104.             $this->warn->addDocWarning($this->currentFile, "variable", $variable["name"], $msg, "mismatch");
  105.             
  106.         } else if ("unknown" == $variable["type"] && "" != $variable["var"]["type"]) {
  107.             
  108.             $variable["type"] = $variable["var"]["type"];
  109.             
  110.         }
  111.         
  112.         if ("" != $variable["var"]["name"] && $variable["var"]["name"] != $variable["name"]) {
  113.             
  114.             $msg = sprintf("The documented class variable name does not match the name found. Update the tag to '@var %s [%s]%s'.",
  115.                             ("" != $variable["var"]["type"]) ? $variable["var"]["type"] : $variable["type"],
  116.                             $variable["name"],
  117.                             (isset($variable["var"]["desc"])) ? " " . $variable["var"]["desc"] : ""
  118.                         );
  119.             $this->warn->addDocWarning($this->currentFile, "variable", $variable["name"], $msg, "mismatch");
  120.         }
  121.         
  122.                 
  123.         unset($variable["var"]);
  124.         
  125.         return $variable;
  126.     } // end func checkVarDocs
  127.  
  128. } // end class PhpdocVariableParser
  129. ?>