| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Parses function doc comments.
|
|
|
4 |
*
|
|
|
5 |
* PHP version 5
|
|
|
6 |
*
|
|
|
7 |
* @category PHP
|
|
|
8 |
* @package PHP_CodeSniffer
|
|
|
9 |
* @author Greg Sherwood <gsherwood@squiz.net>
|
|
|
10 |
* @author Marc McIntyre <mmcintyre@squiz.net>
|
|
|
11 |
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
|
|
12 |
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
|
|
13 |
* @version CVS: $Id: FunctionCommentParser.php 270281 2008-12-02 02:38:34Z squiz $
|
|
|
14 |
* @link http://pear.php.net/package/PHP_CodeSniffer
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractParser', true) === false) {
|
|
|
18 |
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractParser not found';
|
|
|
19 |
throw new PHP_CodeSniffer_Exception($error);
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
if (class_exists('PHP_CodeSniffer_CommentParser_ParameterElement', true) === false) {
|
|
|
23 |
$error = 'Class PHP_CodeSniffer_CommentParser_ParameterElement not found';
|
|
|
24 |
throw new PHP_CodeSniffer_Exception($error);
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
if (class_exists('PHP_CodeSniffer_CommentParser_PairElement', true) === false) {
|
|
|
28 |
$error = 'Class PHP_CodeSniffer_CommentParser_PairElement not found';
|
|
|
29 |
throw new PHP_CodeSniffer_Exception($error);
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
if (class_exists('PHP_CodeSniffer_CommentParser_SingleElement', true) === false) {
|
|
|
33 |
$error = 'Class PHP_CodeSniffer_CommentParser_SingleElement not found';
|
|
|
34 |
throw new PHP_CodeSniffer_Exception($error);
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Parses function doc comments.
|
|
|
39 |
*
|
|
|
40 |
* @category PHP
|
|
|
41 |
* @package PHP_CodeSniffer
|
|
|
42 |
* @author Greg Sherwood <gsherwood@squiz.net>
|
|
|
43 |
* @author Marc McIntyre <mmcintyre@squiz.net>
|
|
|
44 |
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
|
|
45 |
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
|
|
46 |
* @version Release: 1.2.1
|
|
|
47 |
* @link http://pear.php.net/package/PHP_CodeSniffer
|
|
|
48 |
*/
|
|
|
49 |
class PHP_CodeSniffer_CommentParser_FunctionCommentParser extends PHP_CodeSniffer_CommentParser_AbstractParser
|
|
|
50 |
{
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* The parameter elements within this function comment.
|
|
|
54 |
*
|
|
|
55 |
* @var array(PHP_CodeSniffer_CommentParser_ParameterElement)
|
|
|
56 |
*/
|
|
|
57 |
private $_params = array();
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* The return element in this function comment.
|
|
|
61 |
*
|
|
|
62 |
* @var PHP_CodeSniffer_CommentParser_PairElement.
|
|
|
63 |
*/
|
|
|
64 |
private $_return = null;
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* The throws element list for this function comment.
|
|
|
68 |
*
|
|
|
69 |
* @var array(PHP_CodeSniffer_CommentParser_PairElement)
|
|
|
70 |
*/
|
|
|
71 |
private $_throws = array();
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
/**
|
|
|
75 |
* Constructs a PHP_CodeSniffer_CommentParser_FunctionCommentParser.
|
|
|
76 |
*
|
|
|
77 |
* @param string $comment The comment to parse.
|
|
|
78 |
* @param PHP_CodeSniffer_File $phpcsFile The file that this comment is in.
|
|
|
79 |
*/
|
|
|
80 |
public function __construct($comment, PHP_CodeSniffer_File $phpcsFile)
|
|
|
81 |
{
|
|
|
82 |
parent::__construct($comment, $phpcsFile);
|
|
|
83 |
|
|
|
84 |
}//end __construct()
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Parses parameter elements.
|
|
|
89 |
*
|
|
|
90 |
* @param array(string) $tokens The tokens that conmpise this sub element.
|
|
|
91 |
*
|
|
|
92 |
* @return PHP_CodeSniffer_CommentParser_ParameterElement
|
|
|
93 |
*/
|
|
|
94 |
protected function parseParam($tokens)
|
|
|
95 |
{
|
|
|
96 |
$param = new PHP_CodeSniffer_CommentParser_ParameterElement(
|
|
|
97 |
$this->previousElement,
|
|
|
98 |
$tokens,
|
|
|
99 |
$this->phpcsFile
|
|
|
100 |
);
|
|
|
101 |
|
|
|
102 |
$this->_params[] = $param;
|
|
|
103 |
return $param;
|
|
|
104 |
|
|
|
105 |
}//end parseParam()
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
/**
|
|
|
109 |
* Parses return elements.
|
|
|
110 |
*
|
|
|
111 |
* @param array(string) $tokens The tokens that conmpise this sub element.
|
|
|
112 |
*
|
|
|
113 |
* @return PHP_CodeSniffer_CommentParser_PairElement
|
|
|
114 |
*/
|
|
|
115 |
protected function parseReturn($tokens)
|
|
|
116 |
{
|
|
|
117 |
$return = new PHP_CodeSniffer_CommentParser_PairElement(
|
|
|
118 |
$this->previousElement,
|
|
|
119 |
$tokens,
|
|
|
120 |
'return',
|
|
|
121 |
$this->phpcsFile
|
|
|
122 |
);
|
|
|
123 |
|
|
|
124 |
$this->_return = $return;
|
|
|
125 |
return $return;
|
|
|
126 |
|
|
|
127 |
}//end parseReturn()
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
/**
|
|
|
131 |
* Parses throws elements.
|
|
|
132 |
*
|
|
|
133 |
* @param array(string) $tokens The tokens that conmpise this sub element.
|
|
|
134 |
*
|
|
|
135 |
* @return PHP_CodeSniffer_CommentParser_PairElement
|
|
|
136 |
*/
|
|
|
137 |
protected function parseThrows($tokens)
|
|
|
138 |
{
|
|
|
139 |
$throws = new PHP_CodeSniffer_CommentParser_PairElement(
|
|
|
140 |
$this->previousElement,
|
|
|
141 |
$tokens,
|
|
|
142 |
'throws',
|
|
|
143 |
$this->phpcsFile
|
|
|
144 |
);
|
|
|
145 |
|
|
|
146 |
$this->_throws[] = $throws;
|
|
|
147 |
return $throws;
|
|
|
148 |
|
|
|
149 |
}//end parseThrows()
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
/**
|
|
|
153 |
* Returns the parameter elements that this function comment contains.
|
|
|
154 |
*
|
|
|
155 |
* Returns an empty array if no parameter elements are contained within
|
|
|
156 |
* this function comment.
|
|
|
157 |
*
|
|
|
158 |
* @return array(PHP_CodeSniffer_CommentParser_ParameterElement)
|
|
|
159 |
*/
|
|
|
160 |
public function getParams()
|
|
|
161 |
{
|
|
|
162 |
return $this->_params;
|
|
|
163 |
|
|
|
164 |
}//end getParams()
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
/**
|
|
|
168 |
* Returns the return element in this fucntion comment.
|
|
|
169 |
*
|
|
|
170 |
* Returns null if no return element exists in the comment.
|
|
|
171 |
*
|
|
|
172 |
* @return PHP_CodeSniffer_CommentParser_PairElement
|
|
|
173 |
*/
|
|
|
174 |
public function getReturn()
|
|
|
175 |
{
|
|
|
176 |
return $this->_return;
|
|
|
177 |
|
|
|
178 |
}//end getReturn()
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
/**
|
|
|
182 |
* Returns the throws elements in this fucntion comment.
|
|
|
183 |
*
|
|
|
184 |
* Returns empty array if no throws elements in the comment.
|
|
|
185 |
*
|
|
|
186 |
* @return array(PHP_CodeSniffer_CommentParser_PairElement)
|
|
|
187 |
*/
|
|
|
188 |
public function getThrows()
|
|
|
189 |
{
|
|
|
190 |
return $this->_throws;
|
|
|
191 |
|
|
|
192 |
}//end getThrows()
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
/**
|
|
|
196 |
* Returns the allowed tags that can exist in a function comment.
|
|
|
197 |
*
|
|
|
198 |
* @return array(string => boolean)
|
|
|
199 |
*/
|
|
|
200 |
protected function getAllowedTags()
|
|
|
201 |
{
|
|
|
202 |
return array(
|
|
|
203 |
'param' => false,
|
|
|
204 |
'return' => true,
|
|
|
205 |
'throws' => false,
|
|
|
206 |
);
|
|
|
207 |
|
|
|
208 |
}//end getAllowedTags()
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
}//end class
|
|
|
212 |
|
|
|
213 |
?>
|