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