File: PhpdocModuleAnalyser.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 (241 lines) | stat: -rw-r--r-- 6,337 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
/**
* Analyses a modulegroup.
*/
class PhpdocModuleAnalyser extends PhpdocAnalyser {

	/**
	* Module data
	* @var	array
	*/
	var $modulegroup		= array();

	/**
	* List of all modules in the modulegroup
	* @var	array
	*/ 
	var $modulelist = array();
	
	/**
	* Puuuh - findUndocumented() needs this.
	* @var	array
	* @see	findUndocumented()
	*/														
	var $undocumentedFields = array(
															"functions"	=> "function",
															"uses"			=> "included file",
															"consts"		=> "constant"
													);

	/**
	* Sets the data of the modulegroup to analyse.
	* 
	* @param	array	Raw modulegroup data from the parser.
	* @access	public
	*/
	function setModulegroup($modulegroup) {
	
		$this->modulegroup = $modulegroup;	
		
	} // end func setModulegroup
	
	function analyse() {

		$this->flag_get = false;
		
		$this->buildModulelist();
		
		$this->updateAccessReturn();
		$this->updateBrothersSisters();
		
		$this->checkFunctionArgs();
		$this->findUndocumented();
		
	} // end func analyse
	
	/**
	* Returns a module from the modulegroup or false if there are no more modules.
	*
	* @return	mixed		False if there no more modules in the modulegroup otherwise
	* 								an array with the data of a module.
	* @access	public
	*/
	function getModule() {
	
		if (!$this->flag_get) {
			reset($this->modulelist);
			$this->flag_get = true;
		}
			
		if (list($modulename, $group)=each($this->modulelist)) {
			
			$module = $this->modulegroup[$group][$modulename];
			unset($this->modulegroup[$group][$modulename]);			
			return $module;
			
		} else {
		
			return false;
			
		}
		
	} // end func getModule
	
	function findUndocumented() {

		reset($this->modulegroup);
		while (list($group, $modules)=each($this->modulegroup)) {
			
			reset($modules);
			while (list($name, $module)=each($modules)) {
				
				reset($this->undocumentedFields);
				while (list($index, $eltype)=each($this->undocumentedFields)) {
					if (!isset($module[$index]))
						continue;
						
					$file = $module["filename"];
					
					reset($module[$index]);
					while (list($elname, $data)=each($module[$index]))
						if (isset($data["undoc"]) && $data["undoc"])
							$this->warn->addDocWarning($file, $eltype, $elname, "Undocumented element.", "missing");
				}
				
			}
			
		}		

	} // end func findUndocumented
	
	function checkFunctionArgs() {
	
		reset($this->modulegroup);
		while (list($group, $modules)=each($this->modulegroup)) {

			reset($modules);
			while (list($name, $module)=each($modules)) {
				if (!isset($module["functions"]))
					continue;

				$file = $module["filename"];
								
				reset($module["functions"]);
				while (list($fname, $function)=each($module["functions"])) {
					$this->modulegroup[$group][$name]["functions"][$fname]["params"] = $this->checkArgDocs($function["args"], $function["params"], $fname, $file, false);
					unset($this->modulegroup[$group][$name]["functions"][$fname]["args"]);
				}
				
			}
			
		}

	} // end func checkFunctionArgs
	
	/**
	* Builds an internal list of all modules in the modulegroup.
	* @see	$modulelist, $modulegroup
	*/
	function buildModulelist() {
	
		$this->modulelist = array();
		
		reset($this->modulegroup);
		while (list($group, $modules)=each($this->modulegroup)) {
		
			reset($modules);
			while (list($modulename, $data)=each($modules))
				$this->modulelist[$modulename] = $group;
				
		}
		
	}

		
	function updateBrothersSisters() {
	
		reset($this->modulelist);
		while (list($modulename, $group)=each($this->modulelist)) {
			$this->updateBrotherSisterElements($group, $modulename, "functions");
			$this->updateBrotherSisterElements($group, $modulename, "variables");
		}	
		
	} // end func updateBrothersSisters
	
	function updateBrotherSisterElements($group, $modulename, $type) {
		
		if (!isset($this->modulegroup[$group][$modulename][$type])) 
			return false;
			
		reset($this->modulegroup[$group][$modulename][$type]);
		while (list($elementname, $data)=each($this->modulegroup[$group][$modulename][$type])) {
			
			if (isset($data["brother"])) {

				$name = ( "functions" == $type ) ? substr($data["brother"], 0, -2) : substr($data["brother"], 1);
				$name = strtolower($name);

				if (!isset($this->modulegroup[$group][$modulename][$type][$name])) {
					$this->warn->addDocWarning($this->modulegroup[$group][$modulename]["filename"], $type, $elementname, "Brother '$name' is unknown. Tags gets ignored.", "mismatch");
					unset($this->modulegroup[$group][$modulename][$type][$elementname]["brother"]);
				} else {
					$this->modulegroup[$group][$modulename][$type][$elementname]["brother"] = $name;
				}

			}
			
		}
		
	} // end func updateBrotherSistersElements
	
	function updateAccessReturn() {
		
		reset($this->modulelist);
		while (list($modulename, $group)=each($this->modulelist)) {
		
			if (!isset($this->modulegroup[$group][$modulename]["access"]))
				$this->modulegroup[$group][$modulename]["access"] = "private";
				
			$this->updateAccessReturnElements($group, $modulename, "functions");
			$this->updateAccessReturnElements($group, $modulename, "variables");
			$this->updateAccessElements($group, $modulename, "consts");		
			
		}
				
	} // end func updateAccessReturn
	
	function updateAccessReturnElements($group, $modulename, $type) {
		
		if (!isset($this->modulegroup[$group][$modulename][$type]))
			return false;

		reset($this->modulegroup[$group][$modulename][$type]);
		while (list($elementname, $data)=each($this->modulegroup[$group][$modulename][$type])) {
		
			if (!isset($data["access"])) 
				$this->modulegroup[$group][$modulename][$type][$elementname]["access"] = "private";
				
			if (!isset($data["return"]))
				$this->modulegroup[$group][$modulename][$type][$elementname]["return"] = "void";
				
		}
				
	} // end func updateAccessReturnElements
	
	function updateAccessElements($group, $modulename, $type) {
		
		if (!isset($this->modulegroup[$group][$modulename][$type]))
			return false;
			
		reset($this->modulegroup[$group][$modulename][$type]);
		while (list($elementname, $data)=each($this->modulegroup[$group][$modulename][$type])) {
			
			if (!isset($data["access"])) 
				$this->modulegroup[$group][$modulename][$type][$elementname]["access"] = "private";
		
		}
		
	} // end func updateAccessElements
	
} // end class PhpdocModuleAnalyser
?>