changed git call from https to git readonly
[atutor.git] / mods / phpdoc / PHPDoc / parser / PhpdocFunctionParser.php
1 <?php\r
2 /**\r
3 * Looks for documented and undocumented functions within a block of php code.\r
4 *\r
5 * @version $Id: PhpdocFunctionParser.php,v 1.2 2000/12/03 22:37:37 uw Exp $\r
6 */\r
7 class PhpdocFunctionParser extends PhpdocVariableParser {\r
8 \r
9         /**\r
10         * Internal structur of a function.\r
11         *\r
12         * @var  array   $emptyFunction\r
13         */\r
14         var $emptyFunction = array(\r
15                                                                                                                         "name"                                  => "",\r
16                                                                                                                         "undoc"                                 => true,\r
17                                                                                                                         \r
18                                                                                                                         "args"                                  => array()\r
19                                                                                                 );\r
20                 \r
21         /**\r
22         * Array of tags that are allowed in front of the function keyword\r
23         * @var  array   $functionTags\r
24         * @see  analyseFunctionParagraph()\r
25         */\r
26         var $functionTags = array(\r
27                                                                                                                         "parameter"             => true,\r
28                                                                                                                         "param"                         => true,\r
29                                                                                                                         \r
30                                                                                                                         "return"                        => true,\r
31                                                                                                                         \r
32                                                                                                                         "access"                        => true,\r
33                                                                                                                         "abstract"              => true,\r
34                                                                                                                         "static"                        => true,\r
35                                                                                                                         \r
36                                                                                                                         "throws"                        => true,\r
37                                                                                                                         \r
38                                                                                                                         "see"                                   => true,\r
39                                                                                                                         "link"                          => true,\r
40                                                                                                                         \r
41                                                                                                                         "global"                        => true,\r
42                                                                                                                         \r
43                                                                                                                         "version"                       => true,\r
44                                                                                                                         "since"                         => true,\r
45                                                                                                                         \r
46                                                                                                                         "deprecated"    => true,\r
47                                                                                                                         "deprec"                        => true,\r
48                                                                                                                         \r
49                                                                                                                         "brother"                       => true,\r
50                                                                                                                         "sister"                        => true,\r
51                                                                                                                         \r
52                                                                                                                         "exclude"               => true,\r
53                                                                                                                         "magic"                         => true,\r
54                                                                                                                         \r
55                                                                                                                         "author"                        => true,\r
56                                                                                                                         "copyright"             => true,\r
57                                                                                                                         \r
58                                                                                                                         "todo"                          => true\r
59                                                                                         );\r
60         \r
61         /**\r
62         * Analyses a function doc comment.\r
63         * @param        array\r
64         * @return array\r
65         */\r
66         function analyseFunction($para) {\r
67         \r
68                 $function = $this->emptyFunction;\r
69                 $function["name"] = $para["name"];              \r
70 \r
71                 if (""!=$para["doc"]) {\r
72 \r
73                         $function = $this->analyseTags($this->getTags($para["doc"]), $function, $this->functionTags);\r
74                         \r
75                         list($msg, $function) = $this->checkParserErrors($function, "function");\r
76                         if (""!=$msg) \r
77                                 $this->warn->addDocWarning($this->currentFile, "function", $function["name"], $msg, "mismatch");\r
78                         \r
79                         list($function["sdesc"], $function["desc"]) = $this->getDescription($para["doc"]);\r
80                         \r
81                         $function["undoc"] = false;\r
82                         \r
83                 } \r
84 \r
85                 $function["args"] = $this->getFunctionArgs($para["head"]);                      \r
86                 return $function;\r
87         } // end func analyseFunction\r
88         \r
89         /**\r
90         * Analyses a function head and returns an array of arguments.\r
91         * @param        string  PHP code to examine.\r
92         * @return       array           Array of arguments: $args[] = array( optional, default, type, name ).\r
93         * @see  getVariableTypeAndValue()\r
94         */                              \r
95         function getFunctionArgs($code) {\r
96 \r
97                 $args = array();\r
98                 while (preg_match($this->PHP_COMPLEX["argument"], $code, $regs)) {\r
99 \r
100                         $type           = "";\r
101                         $value          = "";\r
102                         $optional = false;\r
103                 \r
104                         if (!isset($regs[3])) {\r
105                                 \r
106                                 $len_of_value = strlen($regs[1]);\r
107                                 \r
108                         } else if ("=" == $regs[3]) {\r
109                 \r
110                                 $find   = $regs[1].$regs[2];\r
111                                 $code   = substr($code, strpos($code, $find)+strlen($find) );\r
112                                 \r
113                                 list ($type, $value, $raw_value) = $this->getVariableTypeAndValue($code);\r
114                                 $len_of_value = strlen($raw_value);\r
115                                 $optional = true;\r
116                         \r
117                         } else {\r
118                                 \r
119                                 $len_of_value = strlen($regs[1].$regs[2]);\r
120                                 \r
121                         }\r
122                         \r
123                         $code = substr($code, $len_of_value);\r
124                         $args[] = array(\r
125                                                                                                 "optional" => $optional, \r
126                                                                                                 "default"  => $value,\r
127                                                                                                 "type"           => $type,\r
128                                                                                                 "name"           => $regs[1]\r
129                                                                                         );\r
130                                                                                                                 \r
131                 }\r
132 \r
133                 return $args;\r
134         } // end func getFunctionArgs\r
135         \r
136 } // end class PhpdocFunctionParser\r
137 ?>