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 / PhpdocConstantParser.php < prev    next >
PHP Script  |  2001-02-18  |  4KB  |  109 lines

  1. <?php
  2. /**
  3. * Extracts define statements and their documentation from php code.
  4. *
  5. * @version $Id: PhpdocConstantParser.php,v 1.5 2001/02/18 14:45:27 uw Exp $
  6. */
  7. class PhpdocConstantParser extends PhpdocUseParser {
  8.  
  9.     /**
  10.     * Internal structure use to save a constant.
  11.     * 
  12.     * @var  array
  13.     */
  14.     var $emptyConstant = array( 
  15.                                 "name"  => "",
  16.                                 "value" => "",
  17.                                 "undoc" => true
  18.                             );
  19.         
  20.     /**
  21.     * Doc Tags allowed with const[ant].
  22.     * 
  23.     * @var  array
  24.     */
  25.     var $constantTags = array(
  26.                                 "access"    => true,
  27.                                 "see"       => true,
  28.                                 "link"      => true,
  29.                                 
  30.                                 "constant"  => true,
  31.                                 "const"     => true,
  32.                                 
  33.                                 "author"    => true,
  34.                                 "copyright" => true,
  35.                                 
  36.                                 "exclude"   => true,
  37.                                 "magic"     => true,
  38.                                 "todo"      => true
  39.                           );
  40.  
  41.     /**
  42.     * Scans the given constant doc comment.
  43.     *
  44.     * @param    array
  45.     */                                                    
  46.     function analyseConstant($para) {
  47.     
  48.         $constant = $this->emptyConstant;
  49.         $constant["name"] = $para["name"];
  50.         $constant["value"] = $para["value"];
  51.         
  52.         if ("" != $para["doc"]) {
  53.         
  54.             $constant = $this->analyseTags( $this->getTags($para["doc"]), $constant, $this->constantTags);
  55.         
  56.             list($msg, $constant) = $this->checkParserErrors($constant, "constant (define() keyword)");
  57.             if ("" != $msg)
  58.                 $this->warn->addDocWarning($this->currentFile, "constant", $constant["name"], $msg, "mismatch");
  59.                 
  60.             list($constant["sdesc"], $constant["desc"]) = $this->getDescription($para["doc"]);
  61.  
  62.             $constant["undoc"] = false;            
  63.         }
  64.         
  65.         $constant = $this->checkConstantDoc($constant);
  66.         
  67.         if (isset($para["case"]))
  68.             $constant["case"] = $para["case"];
  69.         
  70.         return $constant;
  71.     } // end func analyseConstant
  72.     
  73.     /**
  74.     * Compares the data from the parser with the optional const[ant] tags
  75.     * @param    array    Hash with the data of the current constant paragraph
  76.     * @return    array $constant
  77.     */
  78.     function checkConstantDoc($constant) {
  79.     
  80.         if (!isset($constant["const"])) {
  81.         
  82.             $msg = "The @const[ant] tag is missing. Add '@const " . $constant["name"] . " [description]' to the tag list at the end of the doc comment.";
  83.             $this->warn->addDocWarning($this->currentFile, "constant", $constant["name"], $msg, "missing");
  84.  
  85.         } else {
  86.             
  87.             if ($constant["name"] != $constant["const"]["name"]) {
  88.                 
  89.                 $msg = sprintf("The name of the constant '%s' does not match the documented name '%s', update the tag to '@const %s %s'.",
  90.                                 $constant["name"],
  91.                                 $constant["const"]["name"],
  92.                                 $constant["name"],
  93.                                 $constant["const"]["desc"]
  94.                             );
  95.                 $this->warn->addDocWarning($this->currentFile, "constant", $constant["name"], $msg, "mismatch");
  96.                 
  97.             }
  98.  
  99.             if ("" != $constant["const"]["desc"])
  100.                 $constant["const"] = $constant["const"]["desc"];
  101.             else 
  102.                 unset($constant["const"]);
  103.         }
  104.         
  105.         return $constant;
  106.     } // end func checkConstantDoc
  107.  
  108. } // end class PhpdocConstantParser
  109. ?>