File: PhpdocConstantParser.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 (94 lines) | stat: -rw-r--r-- 2,816 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
<?php
/**
* Extracts define statements and their documentation from php code.
* @author	Ulf Wendel <ulf.wendel@redsys.de>
* @version 0.1alpha
*/
class PhpdocConstantParser extends PhpdocUseParser {

	var $emptyConstant = array( 
															"name"						=> "",
															"value"						=> "",
															"undoc"						=> true
														);
														
	var $constantTags = array(
															"access"		=> true,
															"see"				=> true,
															"link"			=> true,
															
															"constant"	=> true,
															"const"			=> true,
															
															"author"		=> true,
															"copyright"	=> true,
															
															"exclude"	=> true,
															"magic"			=> true,
															"todo"			=> true
													);

	function analyseConstant($para) {
	
		$constant = $this->emptyConstant;
		$constant["name"] = $para["name"];
		$constant["value"] = $para["value"];
		
		if (""!=$para["doc"]) {
		
			$constant = $this->analyseTags( $this->getTags($para["doc"]), $constant, $this->constantTags);
		
			list($msg, $constant) = $this->checkParserErrors($constant, "constant (define() keyword)");
			if (""!=$msg)
				$this->warn->addDocWarning($this->currentFile, "constant", $constant["name"], $msg, "mismatch");
				
			list($constant["sdesc"], $constant["desc"])=$this->getDescription($para["doc"]);

			$constant["undoc"] = false;			
		}
		
		$constant = $this->checkConstantDoc($constant);
		
		if (isset($para["case"]))
			$constant["case"] = $para["case"];
		
		return $constant;
	} // end func analyseConstant
	
	/**
	* Compares the data from the parser with the optional @const[ant] tags
	* @param	array	Hash with the data of the current constant paragraph
	* @return	array $constant
	*/
	function checkConstantDoc($constant) {
	
		if (!isset($constant["const"])) {
		
			$msg = "The @const[ant] tag is missing. Add '@const ".$constant["name"]." [description]' to the tag list at the end of the doc comment.";
			$this->warn->addDocWarning($this->currentFile, "constant", $constant["name"], $msg, "missing");

		} else {
			
			if ($constant["name"] != $constant["const"]["name"]) {
				
				$msg = sprintf("The name of the constant '%s' does not match the documented name '%s', update the tag to '@const %s %s'.",
												$constant["name"],
												$constant["const"]["name"],
												$constant["name"],
												$constant["const"]["desc"]
											);
				$this->warn->addDocWarning($this->currentFile, "constant", $constant["name"], $msg, "mismatch");
				
			}

			if (""!=$constant["const"]["desc"])		
				$constant["const"] = $constant["const"]["desc"];
			else 
				unset($constant["const"]);
		}
		
		return $constant;
	} // end func checkConstantDoc
														
} // end class PhpdocConstantParser
?>