File: PhpdocFunctionParser.php

package info (click to toggle)
php4 4.0.3pl1-0potato3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 15,168 kB
  • ctags: 20,556
  • sloc: ansic: 155,237; php: 10,827; sh: 9,608; yacc: 1,874; lex: 1,742; makefile: 788; java: 424; awk: 359; cpp: 335; perl: 181; xml: 57
file content (138 lines) | stat: -rw-r--r-- 3,532 bytes parent folder | download
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Looks for documented and undocumented functions within a block of php code
* @author	Ulf Wendel <ulf@redsys.de>
* @version 0.2
*/
class PhpdocFunctionParser extends PhpdocVariableParser {

	/**
	* Internal structur of a function.
	* @var	array	$emptyFunction
	* @see	functions, analyseFunctionParagraph()
	*/
	var $emptyFunction = array(
	
															"name"					=> "",
															"undoc"					=> true,
															
															"args"					=> array()
												);
		
	/**
	* Array of tags that are allowed in front of the function keyword
	* @var	array	$functionTags
	* @see	analyseFunctionParagraph()
	*/
	var $functionTags = array(
															"parameter"	 	=> true,
															"param"				=> true,
															
															"return"			=> true,
															
															"access"			=> true,
															"abstract"		=> true,
															"static"			=> true,
															
															"throws"			=> true,
															
															"see"					=> true,
															"link"				=> true,
															
															"global"			=> true,
															
															"version"			=> true,
															"since"				=> true,
															
															"deprecated"	=> true,
															"deprec"			=> true,
															
															"brother"			=> true,
															"sister"			=> true,
															
															"exclude"		=> true,
															"magic"				=> true,
															
															"author"			=> true,
															"copyright"		=> true,
															
															"todo"				=> true
											);
	
	/**
	* Analyses a function doc comment.
	* @param	array
	* @return array
	*/
	function analyseFunction($para) {
	
		$function = $this->emptyFunction;
		$function["name"] = $para["name"];		

		if (""!=$para["doc"]) {

			$function = $this->analyseTags($this->getTags($para["doc"]), $function, $this->functionTags);
			
			list($msg, $function) = $this->checkParserErrors($function, "function");
			if (""!=$msg) 
				$this->warn->addDocWarning($this->currentFile, "function", $function["name"], $msg, "mismatch");
			
			list($function["sdesc"], $function["desc"]) = $this->getDescription($para["doc"]);
			
			$function["undoc"] = false;
			
		} 

		$function["args"] = $this->getFunctionArgs($para["head"]);			
		return $function;
	} // end func analyseFunction
	
	/**
	* Analyses a function head and returns an array of arguments.
	* @param	string	PHP code to examine.
	* @return	array		Array of arguments: $args[] = array( optional, default, type, name ).
	* @see	getVariableTypeAndValue()
	*/				
	function getFunctionArgs($code) {

		$args = array();
		while (preg_match($this->PHP_COMPLEX["argument"], $code, $regs)) {

			$type 		= "";
			$value 		= "";
			$optional = false;
		
			if (!isset($regs[3])) {
				
				$len_of_value = strlen($regs[1]);
				
			} else if ("=" == $regs[3]) {
		
				$find 	= $regs[1].$regs[2];
				$code 	= substr($code, strpos($code, $find)+strlen($find) );
				
				list ($type, $value, $raw_value) = $this->getVariableTypeAndValue($code);
				$len_of_value = strlen($raw_value);
				$optional = true;
			
			} else {
				
				$len_of_value = strlen($regs[1].$regs[2]);
				
			}
			
			$code = substr($code, $len_of_value);
			$args[] = array(
												"optional" => $optional, 
												"default"  => $value,
												"type"		 => $type,
												"name"		 => $regs[1]
											);
														
		}

		return $args;
	} // end func getFunctionArgs
	
} // end class PhpdocFunctionParser
?>