3
* A class to represent single element doc tags.
8
* @package PHP_CodeSniffer
9
* @author Greg Sherwood <gsherwood@squiz.net>
10
* @author Marc McIntyre <mmcintyre@squiz.net>
11
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
12
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
13
* @link http://pear.php.net/package/PHP_CodeSniffer
16
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
17
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
18
throw new PHP_CodeSniffer_Exception($error);
22
* A class to represent single element doc tags.
24
* A single element doc tag contains only one value after the tag itself. An
25
* example would be the \@package tag.
28
* @package PHP_CodeSniffer
29
* @author Greg Sherwood <gsherwood@squiz.net>
30
* @author Marc McIntyre <mmcintyre@squiz.net>
31
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
32
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
33
* @version Release: 1.5.5
34
* @link http://pear.php.net/package/PHP_CodeSniffer
36
class PHP_CodeSniffer_CommentParser_SingleElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
40
* The content that exists after the tag.
45
protected $content = '';
48
* The whitespace that exists before the content.
51
* @see getWhitespaceBeforeContent()
53
protected $contentWhitespace = '';
57
* Constructs a SingleElement doc tag.
59
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
62
* @param array $tokens The tokens
65
* @param string $tag The tag that
68
* @param PHP_CodeSniffer_File $phpcsFile The file that
72
public function __construct(
76
PHP_CodeSniffer_File $phpcsFile
78
parent::__construct($previousElement, $tokens, $tag, $phpcsFile);
84
* Returns the element names that this tag is comprised of, in the order
85
* that they appear in the tag.
88
* @see processSubElement()
90
protected function getSubElements()
92
return array('content');
94
}//end getSubElements()
98
* Processes the sub element with the specified name.
100
* @param string $name The name of the sub element to process.
101
* @param string $content The content of this sub element.
102
* @param string $whitespaceBefore The whitespace that exists before the
106
* @see getSubElements()
108
protected function processSubElement($name, $content, $whitespaceBefore)
110
$this->content = $content;
111
$this->contentWhitespace = $whitespaceBefore;
113
}//end processSubElement()
117
* Returns the content of this tag.
121
public function getContent()
123
return $this->content;
129
* Returns the whitespace before the content of this tag.
133
public function getWhitespaceBeforeContent()
135
return $this->contentWhitespace;
137
}//end getWhitespaceBeforeContent()
141
* Processes a content check for single doc element.
143
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
144
* @param int $commentStart The line number where
146
* @param string $docBlock Whether this is a file or
151
public function process(
152
PHP_CodeSniffer_File $phpcsFile,
156
if ($this->content === '') {
157
$errorPos = ($commentStart + $this->getLine());
158
$error = 'Content missing for %s tag in %s comment';
163
$phpcsFile->addError($error, $errorPos, 'EmptyTagContent', $data);