| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* A class to represent single element doc tags.
|
|
|
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: SingleElement.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_AbstractDocElement', true) === false) {
|
|
|
18 |
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
|
|
|
19 |
throw new PHP_CodeSniffer_Exception($error);
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* A class to represent single element doc tags.
|
|
|
24 |
*
|
|
|
25 |
* A single element doc tag contains only one value after the tag itself. An
|
|
|
26 |
* example would be the \@package tag.
|
|
|
27 |
*
|
|
|
28 |
* @category PHP
|
|
|
29 |
* @package PHP_CodeSniffer
|
|
|
30 |
* @author Greg Sherwood <gsherwood@squiz.net>
|
|
|
31 |
* @author Marc McIntyre <mmcintyre@squiz.net>
|
|
|
32 |
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
|
|
33 |
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
|
|
34 |
* @version Release: 1.2.1
|
|
|
35 |
* @link http://pear.php.net/package/PHP_CodeSniffer
|
|
|
36 |
*/
|
|
|
37 |
class PHP_CodeSniffer_CommentParser_SingleElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
|
|
|
38 |
{
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* The content that exists after the tag.
|
|
|
42 |
*
|
|
|
43 |
* @var string
|
|
|
44 |
* @see getContent()
|
|
|
45 |
*/
|
|
|
46 |
protected $content = '';
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* The whitespace that exists before the content.
|
|
|
50 |
*
|
|
|
51 |
* @var string
|
|
|
52 |
* @see getWhitespaceBeforeContent()
|
|
|
53 |
*/
|
|
|
54 |
protected $contentWhitespace = '';
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Constructs a SingleElement doc tag.
|
|
|
59 |
*
|
|
|
60 |
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
|
|
|
61 |
* before this
|
|
|
62 |
* one.
|
|
|
63 |
* @param array $tokens The tokens
|
|
|
64 |
* that comprise
|
|
|
65 |
* this element.
|
|
|
66 |
* @param string $tag The tag that
|
|
|
67 |
* this element
|
|
|
68 |
* represents.
|
|
|
69 |
* @param PHP_CodeSniffer_File $phpcsFile The file that
|
|
|
70 |
* this element
|
|
|
71 |
* is in.
|
|
|
72 |
*/
|
|
|
73 |
public function __construct(
|
|
|
74 |
$previousElement,
|
|
|
75 |
$tokens,
|
|
|
76 |
$tag,
|
|
|
77 |
PHP_CodeSniffer_File $phpcsFile
|
|
|
78 |
) {
|
|
|
79 |
parent::__construct($previousElement, $tokens, $tag, $phpcsFile);
|
|
|
80 |
|
|
|
81 |
}//end __construct()
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Returns the element names that this tag is comprised of, in the order
|
|
|
86 |
* that they appear in the tag.
|
|
|
87 |
*
|
|
|
88 |
* @return array(string)
|
|
|
89 |
* @see processSubElement()
|
|
|
90 |
*/
|
|
|
91 |
protected function getSubElements()
|
|
|
92 |
{
|
|
|
93 |
return array('content');
|
|
|
94 |
|
|
|
95 |
}//end getSubElements()
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
/**
|
|
|
99 |
* Processes the sub element with the specified name.
|
|
|
100 |
*
|
|
|
101 |
* @param string $name The name of the sub element to process.
|
|
|
102 |
* @param string $content The content of this sub element.
|
|
|
103 |
* @param string $whitespaceBefore The whitespace that exists before the
|
|
|
104 |
* sub element.
|
|
|
105 |
*
|
|
|
106 |
* @return void
|
|
|
107 |
* @see getSubElements()
|
|
|
108 |
*/
|
|
|
109 |
protected function processSubElement($name, $content, $whitespaceBefore)
|
|
|
110 |
{
|
|
|
111 |
$this->content = $content;
|
|
|
112 |
$this->contentWhitespace = $whitespaceBefore;
|
|
|
113 |
|
|
|
114 |
}//end processSubElement()
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* Returns the content of this tag.
|
|
|
119 |
*
|
|
|
120 |
* @return string
|
|
|
121 |
*/
|
|
|
122 |
public function getContent()
|
|
|
123 |
{
|
|
|
124 |
return $this->content;
|
|
|
125 |
|
|
|
126 |
}//end getContent()
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
/**
|
|
|
130 |
* Returns the witespace before the content of this tag.
|
|
|
131 |
*
|
|
|
132 |
* @return string
|
|
|
133 |
*/
|
|
|
134 |
public function getWhitespaceBeforeContent()
|
|
|
135 |
{
|
|
|
136 |
return $this->contentWhitespace;
|
|
|
137 |
|
|
|
138 |
}//end getWhitespaceBeforeContent()
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
/**
|
|
|
142 |
* Processes a content check for single doc element.
|
|
|
143 |
*
|
|
|
144 |
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
|
|
145 |
* @param int $commentStart The line number where
|
|
|
146 |
* the error occurs.
|
|
|
147 |
* @param string $docBlock Whether this is a file or
|
|
|
148 |
* class comment doc.
|
|
|
149 |
*
|
|
|
150 |
* @return void
|
|
|
151 |
*/
|
|
|
152 |
public function process(
|
|
|
153 |
PHP_CodeSniffer_File $phpcsFile,
|
|
|
154 |
$commentStart,
|
|
|
155 |
$docBlock
|
|
|
156 |
) {
|
|
|
157 |
if ($this->content === '') {
|
|
|
158 |
$errorPos = ($commentStart + $this->getLine());
|
|
|
159 |
$error = "Content missing for $this->tag tag in $docBlock comment";
|
|
|
160 |
$phpcsFile->addError($error, $errorPos);
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
}//end process()
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
}//end class
|
|
|
167 |
|
|
|
168 |
?>
|