Initial Commit
This commit is contained in:
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to handle most of the parsing operations of a doc comment element.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (interface_exists('PHP_CodeSniffer_CommentParser_DocElement', true) === false) {
|
||||
$error = 'Interface PHP_CodeSniffer_CommentParser_DocElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to handle most of the parsing operations of a doc comment element.
|
||||
*
|
||||
* Extending classes should implement the getSubElements method to return
|
||||
* a list of elements that the doc comment element contains, in the order that
|
||||
* they appear in the element. For example a function parameter element has a
|
||||
* type, a variable name and a comment. It should therefore implement the method
|
||||
* as follows:
|
||||
*
|
||||
* <code>
|
||||
* protected function getSubElements()
|
||||
* {
|
||||
* return array(
|
||||
* 'type',
|
||||
* 'variable',
|
||||
* 'comment',
|
||||
* );
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* The processSubElement will be called for each of the sub elements to allow
|
||||
* the extending class to process them. So for the parameter element we would
|
||||
* have:
|
||||
*
|
||||
* <code>
|
||||
* protected function processSubElement($name, $content, $whitespaceBefore)
|
||||
* {
|
||||
* if ($name === 'type') {
|
||||
* echo 'The name of the variable was '.$content;
|
||||
* }
|
||||
* // Process other tags.
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
abstract class PHP_CodeSniffer_CommentParser_AbstractDocElement implements PHP_CodeSniffer_CommentParser_DocElement
|
||||
{
|
||||
|
||||
/**
|
||||
* The element previous to this element.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_DocElement
|
||||
*/
|
||||
protected $previousElement = null;
|
||||
|
||||
/**
|
||||
* The element proceeding this element.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_DocElement
|
||||
*/
|
||||
protected $nextElement = null;
|
||||
|
||||
/**
|
||||
* The whitespace the occurs after this element and its sub elements.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $afterWhitespace = '';
|
||||
|
||||
/**
|
||||
* The tokens that comprise this element.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
protected $tokens = array();
|
||||
|
||||
/**
|
||||
* The file this element is in.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
protected $phpcsFile = null;
|
||||
|
||||
/**
|
||||
* The tag that this element represents (omiting the @ symbol).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag = '';
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a Doc Element.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
|
||||
* that ocurred
|
||||
* before this.
|
||||
* @param array $tokens The tokens of
|
||||
* this element.
|
||||
* @param string $tag The doc
|
||||
* element tag
|
||||
* this element
|
||||
* represents.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that
|
||||
* this element
|
||||
* is in.
|
||||
*
|
||||
* @throws Exception If $previousElement in not a DocElement or if
|
||||
* getSubElements() does not return an array.
|
||||
*/
|
||||
public function __construct(
|
||||
$previousElement,
|
||||
array $tokens,
|
||||
$tag,
|
||||
PHP_CodeSniffer_File $phpcsFile
|
||||
) {
|
||||
if ($previousElement !== null
|
||||
&& ($previousElement instanceof PHP_CodeSniffer_CommentParser_DocElement) === false
|
||||
) {
|
||||
$error = '$previousElement must be an instance of DocElement';
|
||||
throw new Exception($error);
|
||||
}
|
||||
|
||||
$this->phpcsFile = $phpcsFile;
|
||||
|
||||
$this->previousElement = $previousElement;
|
||||
if ($previousElement !== null) {
|
||||
$this->previousElement->nextElement = $this;
|
||||
}
|
||||
|
||||
$this->tag = $tag;
|
||||
$this->tokens = $tokens;
|
||||
|
||||
$subElements = $this->getSubElements();
|
||||
|
||||
if (is_array($subElements) === false) {
|
||||
throw new Exception('getSubElements() must return an array');
|
||||
}
|
||||
|
||||
$whitespace = '';
|
||||
$currElem = 0;
|
||||
$lastElement = '';
|
||||
$lastElementWhitespace = null;
|
||||
$numSubElements = count($subElements);
|
||||
|
||||
foreach ($this->tokens as $token) {
|
||||
if (trim($token) === '') {
|
||||
$whitespace .= $token;
|
||||
} else {
|
||||
if ($currElem < ($numSubElements - 1)) {
|
||||
$element = $subElements[$currElem];
|
||||
$this->processSubElement($element, $token, $whitespace);
|
||||
$whitespace = '';
|
||||
$currElem++;
|
||||
} else {
|
||||
if ($lastElementWhitespace === null) {
|
||||
$lastElementWhitespace = $whitespace;
|
||||
}
|
||||
|
||||
$lastElement .= $whitespace.$token;
|
||||
$whitespace = '';
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
$lastElement = ltrim($lastElement);
|
||||
$lastElementName = $subElements[($numSubElements - 1)];
|
||||
|
||||
// Process the last element in this tag.
|
||||
$this->processSubElement(
|
||||
$lastElementName,
|
||||
$lastElement,
|
||||
$lastElementWhitespace
|
||||
);
|
||||
|
||||
$this->afterWhitespace = $whitespace;
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element that exists before this.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_DocElement
|
||||
*/
|
||||
public function getPreviousElement()
|
||||
{
|
||||
return $this->previousElement;
|
||||
|
||||
}//end getPreviousElement()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element that exists after this.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_DocElement
|
||||
*/
|
||||
public function getNextElement()
|
||||
{
|
||||
return $this->nextElement;
|
||||
|
||||
}//end getNextElement()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace that exists before this element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWhitespaceBefore()
|
||||
{
|
||||
if ($this->previousElement !== null) {
|
||||
return $this->previousElement->getWhitespaceAfter();
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}//end getWhitespaceBefore()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace that exists after this element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWhitespaceAfter()
|
||||
{
|
||||
return $this->afterWhitespace;
|
||||
|
||||
}//end getWhitespaceAfter()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the order that this element appears in the comment.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
if ($this->previousElement === null) {
|
||||
return 1;
|
||||
} else {
|
||||
return ($this->previousElement->getOrder() + 1);
|
||||
}
|
||||
|
||||
}//end getOrder()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the tag that this element represents, ommiting the @ symbol.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return $this->tag;
|
||||
|
||||
}//end getTag()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the raw content of this element, ommiting the tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawContent()
|
||||
{
|
||||
return implode('', $this->tokens);
|
||||
|
||||
}//end getRawContent()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the comment tokens.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTokens()
|
||||
{
|
||||
return $this->tokens;
|
||||
|
||||
}//end getTokens()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the line in which this element first occured.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLine()
|
||||
{
|
||||
if ($this->previousElement === null) {
|
||||
// First element is on line one.
|
||||
return 1;
|
||||
} else {
|
||||
$previousContent = $this->previousElement->getRawContent();
|
||||
$previousLine = $this->previousElement->getLine();
|
||||
|
||||
return ($previousLine + substr_count($previousContent, $this->phpcsFile->eolChar));
|
||||
}
|
||||
|
||||
}//end getLine()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the sub element names that make up this element in the order they
|
||||
* appear in the element.
|
||||
*
|
||||
* @return array(string)
|
||||
* @see processSubElement()
|
||||
*/
|
||||
abstract protected function getSubElements();
|
||||
|
||||
|
||||
/**
|
||||
* Called to process each sub element as sepcified in the return value
|
||||
* of getSubElements().
|
||||
*
|
||||
* @param string $name The name of the element to process.
|
||||
* @param string $content The content of the the element.
|
||||
* @param string $whitespaceBefore The whitespace found before this element.
|
||||
*
|
||||
* @return void
|
||||
* @see getSubElements()
|
||||
*/
|
||||
abstract protected function processSubElement(
|
||||
$name,
|
||||
$content,
|
||||
$whitespaceBefore
|
||||
);
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,684 @@
|
||||
<?php
|
||||
/**
|
||||
* Parses doc comments.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_SingleElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_SingleElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_CommentElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_CommentElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_ParserException', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_ParserException not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses doc comments.
|
||||
*
|
||||
* This abstract parser handles the following tags:
|
||||
*
|
||||
* <ul>
|
||||
* <li>The short description and the long description</li>
|
||||
* <li>@see</li>
|
||||
* <li>@link</li>
|
||||
* <li>@deprecated</li>
|
||||
* <li>@since</li>
|
||||
* </ul>
|
||||
*
|
||||
* Extending classes should implement the getAllowedTags() method to return the
|
||||
* tags that they wish to process, ommiting the tags that this base class
|
||||
* processes. When one of these tags in encountered, the process<tag_name>
|
||||
* method is called on that class. For example, if a parser's getAllowedTags()
|
||||
* method returns \@param as one of its tags, the processParam method will be
|
||||
* called so that the parser can process such a tag.
|
||||
*
|
||||
* The method is passed the tokens that comprise this tag. The tokens array
|
||||
* includes the whitespace that exists between the tokens, as seperate tokens.
|
||||
* It's up to the method to create a element that implements the DocElement
|
||||
* interface, which should be returned. The AbstractDocElement class is a helper
|
||||
* class that can be used to handle most of the parsing of the tokens into their
|
||||
* individual sub elements. It requires that you construct it with the element
|
||||
* previous to the element currently being processed, which can be acquired
|
||||
* with the protected $previousElement class member of this class.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
abstract class PHP_CodeSniffer_CommentParser_AbstractParser
|
||||
{
|
||||
|
||||
/**
|
||||
* The comment element that appears in the doc comment.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_CommentElement
|
||||
*/
|
||||
protected $comment = null;
|
||||
|
||||
/**
|
||||
* The string content of the comment.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $commentString = '';
|
||||
|
||||
/**
|
||||
* The file that the comment exists in.
|
||||
*
|
||||
* @var PHP_CodeSniffer_File
|
||||
*/
|
||||
protected $phpcsFile = null;
|
||||
|
||||
/**
|
||||
* The word tokens that appear in the comment.
|
||||
*
|
||||
* Whitespace tokens also appear in this stack, but are separate tokens
|
||||
* from words.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
protected $words = array();
|
||||
|
||||
/**
|
||||
* An array of all tags found in the comment.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
protected $foundTags = array();
|
||||
|
||||
/**
|
||||
* The previous doc element that was processed.
|
||||
*
|
||||
* null if the current element being processed is the first element in the
|
||||
* doc comment.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_DocElement
|
||||
*/
|
||||
protected $previousElement = null;
|
||||
|
||||
/**
|
||||
* A list of see elements that appear in this doc comment.
|
||||
*
|
||||
* @var array(PHP_CodeSniffer_CommentParser_SingleElement)
|
||||
*/
|
||||
protected $sees = array();
|
||||
|
||||
/**
|
||||
* A list of see elements that appear in this doc comment.
|
||||
*
|
||||
* @var array(PHP_CodeSniffer_CommentParser_SingleElement)
|
||||
*/
|
||||
protected $deprecated = null;
|
||||
|
||||
/**
|
||||
* A list of see elements that appear in this doc comment.
|
||||
*
|
||||
* @var array(PHP_CodeSniffer_CommentParser_SingleElement)
|
||||
*/
|
||||
protected $links = array();
|
||||
|
||||
/**
|
||||
* A element to represent \@since tags.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected $since = null;
|
||||
|
||||
/**
|
||||
* True if the comment has been parsed.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_hasParsed = false;
|
||||
|
||||
/**
|
||||
* The tags that this class can process.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
private static $_tags = array(
|
||||
'see' => false,
|
||||
'link' => false,
|
||||
'deprecated' => true,
|
||||
'since' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* An array of unknown tags.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
public $unknown = array();
|
||||
|
||||
/**
|
||||
* The order of tags.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
public $orders = array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a Doc Comment Parser.
|
||||
*
|
||||
* @param string $comment The comment to parse.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that this comment is in.
|
||||
*/
|
||||
public function __construct($comment, PHP_CodeSniffer_File $phpcsFile)
|
||||
{
|
||||
$this->commentString = $comment;
|
||||
$this->phpcsFile = $phpcsFile;
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Initiates the parsing of the doc comment.
|
||||
*
|
||||
* @return void
|
||||
* @throws PHP_CodeSniffer_CommentParser_ParserException If the parser finds a
|
||||
* problem with the
|
||||
* comment.
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
if ($this->_hasParsed === false) {
|
||||
$this->_parse($this->commentString);
|
||||
}
|
||||
|
||||
}//end parse()
|
||||
|
||||
|
||||
/**
|
||||
* Parse the comment.
|
||||
*
|
||||
* @param string $comment The doc comment to parse.
|
||||
*
|
||||
* @return void
|
||||
* @see _parseWords()
|
||||
*/
|
||||
private function _parse($comment)
|
||||
{
|
||||
// Firstly, remove the comment tags and any stars from the left side.
|
||||
$lines = explode($this->phpcsFile->eolChar, $comment);
|
||||
foreach ($lines as &$line) {
|
||||
$line = trim($line);
|
||||
|
||||
if ($line !== '') {
|
||||
if (substr($line, 0, 3) === '/**') {
|
||||
$line = substr($line, 3);
|
||||
} else if (substr($line, -2, 2) === '*/') {
|
||||
$line = substr($line, 0, -2);
|
||||
} else if ($line{0} === '*') {
|
||||
$line = substr($line, 1);
|
||||
}
|
||||
|
||||
// Add the words to the stack, preserving newlines. Other parsers
|
||||
// might be interested in the spaces between words, so tokenize
|
||||
// spaces as well as separate tokens.
|
||||
$flags = (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$words = preg_split(
|
||||
'|(\s+)|',
|
||||
$line.$this->phpcsFile->eolChar,
|
||||
-1,
|
||||
$flags
|
||||
);
|
||||
|
||||
$this->words = array_merge($this->words, $words);
|
||||
}//end if
|
||||
}//end foreach
|
||||
|
||||
$this->_parseWords();
|
||||
|
||||
}//end _parse()
|
||||
|
||||
|
||||
/**
|
||||
* Parses each word within the doc comment.
|
||||
*
|
||||
* @return void
|
||||
* @see _parse()
|
||||
* @throws PHP_CodeSniffer_CommentParser_ParserException If more than the allowed
|
||||
* number of occurances of
|
||||
* a tag is found.
|
||||
*/
|
||||
private function _parseWords()
|
||||
{
|
||||
$allowedTags = (self::$_tags + $this->getAllowedTags());
|
||||
$allowedTagNames = array_keys($allowedTags);
|
||||
$prevTagPos = false;
|
||||
$wordWasEmpty = true;
|
||||
|
||||
foreach ($this->words as $wordPos => $word) {
|
||||
if (trim($word) !== '') {
|
||||
$wordWasEmpty = false;
|
||||
}
|
||||
|
||||
if ($word{0} === '@') {
|
||||
$tag = substr($word, 1);
|
||||
|
||||
// Filter out @ tags in the comment description.
|
||||
// A real comment tag should have whitespace and a newline before it.
|
||||
if (isset($this->words[($wordPos - 1)]) === false
|
||||
|| trim($this->words[($wordPos - 1)]) !== ''
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($this->words[($wordPos - 2)]) === false
|
||||
|| $this->words[($wordPos - 2)] !== $this->phpcsFile->eolChar
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->foundTags[] = array(
|
||||
'tag' => $tag,
|
||||
'line' => $this->getLine($wordPos),
|
||||
'pos' => $wordPos,
|
||||
);
|
||||
|
||||
if ($prevTagPos !== false) {
|
||||
// There was a tag before this so let's process it.
|
||||
$prevTag = substr($this->words[$prevTagPos], 1);
|
||||
$this->parseTag($prevTag, $prevTagPos, ($wordPos - 1));
|
||||
} else {
|
||||
// There must have been a comment before this tag, so
|
||||
// let's process that.
|
||||
$this->parseTag('comment', 0, ($wordPos - 1));
|
||||
}
|
||||
|
||||
$prevTagPos = $wordPos;
|
||||
|
||||
if (in_array($tag, $allowedTagNames) === false) {
|
||||
// This is not a tag that we process, but let's check to
|
||||
// see if it is a tag we know about. If we don't know about it,
|
||||
// we add it to a list of unknown tags.
|
||||
$knownTags = array(
|
||||
'abstract',
|
||||
'access',
|
||||
'example',
|
||||
'filesource',
|
||||
'global',
|
||||
'ignore',
|
||||
'internal',
|
||||
'name',
|
||||
'static',
|
||||
'staticvar',
|
||||
'todo',
|
||||
'tutorial',
|
||||
'uses',
|
||||
'package_version@',
|
||||
);
|
||||
|
||||
if (in_array($tag, $knownTags) === false) {
|
||||
$this->unknown[] = array(
|
||||
'tag' => $tag,
|
||||
'line' => $this->getLine($wordPos),
|
||||
'pos' => $wordPos,
|
||||
);
|
||||
}
|
||||
}//end if
|
||||
}//end if
|
||||
}//end foreach
|
||||
|
||||
// Only process this tag if there was something to process.
|
||||
if ($wordWasEmpty === false) {
|
||||
if ($prevTagPos === false) {
|
||||
// There must only be a comment in this doc comment.
|
||||
$this->parseTag('comment', 0, count($this->words));
|
||||
} else {
|
||||
// Process the last tag element.
|
||||
$prevTag = substr($this->words[$prevTagPos], 1);
|
||||
$numWords = count($this->words);
|
||||
$endPos = $numWords;
|
||||
|
||||
if ($prevTag === 'package' || $prevTag === 'subpackage') {
|
||||
// These are single-word tags, so anything after a newline
|
||||
// is really a comment.
|
||||
for ($endPos = $prevTagPos; $endPos < $numWords; $endPos++) {
|
||||
if (strpos($this->words[$endPos], $this->phpcsFile->eolChar) !== false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->parseTag($prevTag, $prevTagPos, $endPos);
|
||||
|
||||
if ($endPos !== $numWords) {
|
||||
// Process the final comment, if it is not empty.
|
||||
$tokens = array_slice($this->words, ($endPos + 1), $numWords);
|
||||
$content = implode('', $tokens);
|
||||
if (trim($content) !== '') {
|
||||
$this->parseTag('comment', ($endPos + 1), $numWords);
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
}//end if
|
||||
|
||||
}//end _parseWords()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the line that the token exists on in the doc comment.
|
||||
*
|
||||
* @param int $tokenPos The position in the words stack to find the line
|
||||
* number for.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getLine($tokenPos)
|
||||
{
|
||||
$newlines = 0;
|
||||
for ($i = 0; $i < $tokenPos; $i++) {
|
||||
$newlines += substr_count($this->phpcsFile->eolChar, $this->words[$i]);
|
||||
}
|
||||
|
||||
return $newlines;
|
||||
|
||||
}//end getLine()
|
||||
|
||||
|
||||
/**
|
||||
* Parses see tag element within the doc comment.
|
||||
*
|
||||
* @param array(string) $tokens The word tokens that comprise this element.
|
||||
*
|
||||
* @return DocElement The element that represents this see comment.
|
||||
*/
|
||||
protected function parseSee($tokens)
|
||||
{
|
||||
$see = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'see',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
$this->sees[] = $see;
|
||||
return $see;
|
||||
|
||||
}//end parseSee()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the comment element that appears at the top of the doc comment.
|
||||
*
|
||||
* @param array(string) $tokens The word tokens that comprise tihs element.
|
||||
*
|
||||
* @return DocElement The element that represents this comment element.
|
||||
*/
|
||||
protected function parseComment($tokens)
|
||||
{
|
||||
$this->comment = new PHP_CodeSniffer_CommentParser_CommentElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
return $this->comment;
|
||||
|
||||
}//end parseComment()
|
||||
|
||||
|
||||
/**
|
||||
* Parses \@deprecated tags.
|
||||
*
|
||||
* @param array(string) $tokens The word tokens that comprise tihs element.
|
||||
*
|
||||
* @return DocElement The element that represents this deprecated tag.
|
||||
*/
|
||||
protected function parseDeprecated($tokens)
|
||||
{
|
||||
$this->deprecated = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'deprecated',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
return $this->deprecated;
|
||||
|
||||
}//end parseDeprecated()
|
||||
|
||||
|
||||
/**
|
||||
* Parses \@since tags.
|
||||
*
|
||||
* @param array(string) $tokens The word tokens that comprise this element.
|
||||
*
|
||||
* @return SingleElement The element that represents this since tag.
|
||||
*/
|
||||
protected function parseSince($tokens)
|
||||
{
|
||||
$this->since = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'since',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
return $this->since;
|
||||
|
||||
}//end parseSince()
|
||||
|
||||
|
||||
/**
|
||||
* Parses \@link tags.
|
||||
*
|
||||
* @param array(string) $tokens The word tokens that comprise this element.
|
||||
*
|
||||
* @return SingleElement The element that represents this link tag.
|
||||
*/
|
||||
protected function parseLink($tokens)
|
||||
{
|
||||
$link = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'link',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
$this->links[] = $link;
|
||||
return $link;
|
||||
|
||||
}//end parseLink()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the see elements that appear in this doc comment.
|
||||
*
|
||||
* @return array(SingleElement)
|
||||
*/
|
||||
public function getSees()
|
||||
{
|
||||
return $this->sees;
|
||||
|
||||
}//end getSees()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the comment element that appears at the top of this doc comment.
|
||||
*
|
||||
* @return CommentElement
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->comment;
|
||||
|
||||
}//end getComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the word list.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getWords()
|
||||
{
|
||||
return $this->words;
|
||||
|
||||
}//end getWords()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the list of found tags.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->foundTags;
|
||||
|
||||
}//end getTags()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the link elements found in this comment.
|
||||
*
|
||||
* Returns an empty array if no links are found in the comment.
|
||||
*
|
||||
* @return array(SingleElement)
|
||||
*/
|
||||
public function getLinks()
|
||||
{
|
||||
return $this->links;
|
||||
|
||||
}//end getLinks()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the deprecated element found in this comment.
|
||||
*
|
||||
* Returns null if no element exists in the comment.
|
||||
*
|
||||
* @return SingleElement
|
||||
*/
|
||||
public function getDeprecated()
|
||||
{
|
||||
return $this->deprecated;
|
||||
|
||||
}//end getDeprecated()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the since element found in this comment.
|
||||
*
|
||||
* Returns null if no element exists in the comment.
|
||||
*
|
||||
* @return SingleElement
|
||||
*/
|
||||
public function getSince()
|
||||
{
|
||||
return $this->since;
|
||||
|
||||
}//end getSince()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the specified tag.
|
||||
*
|
||||
* @param string $tag The tag name to parse (omitting the @ sybmol from
|
||||
* the tag)
|
||||
* @param int $start The position in the word tokens where this element
|
||||
* started.
|
||||
* @param int $end The position in the word tokens where this element
|
||||
* ended.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception If the process method for the tag cannot be found.
|
||||
*/
|
||||
protected function parseTag($tag, $start, $end)
|
||||
{
|
||||
$tokens = array_slice($this->words, ($start + 1), ($end - $start));
|
||||
|
||||
$allowedTags = (self::$_tags + $this->getAllowedTags());
|
||||
$allowedTagNames = array_keys($allowedTags);
|
||||
if ($tag === 'comment' || in_array($tag, $allowedTagNames) === true) {
|
||||
$method = 'parse'.$tag;
|
||||
if (method_exists($this, $method) === false) {
|
||||
$error = 'Method '.$method.' must be implemented to process '.$tag.' tags';
|
||||
throw new Exception($error);
|
||||
}
|
||||
|
||||
$this->previousElement = $this->$method($tokens);
|
||||
} else {
|
||||
$this->previousElement = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
$tag,
|
||||
$this->phpcsFile
|
||||
);
|
||||
}
|
||||
|
||||
$this->orders[] = $tag;
|
||||
|
||||
if ($this->previousElement === null
|
||||
|| ($this->previousElement instanceof PHP_CodeSniffer_CommentParser_DocElement) === false
|
||||
) {
|
||||
throw new Exception('Parse method must return a DocElement');
|
||||
}
|
||||
|
||||
}//end parseTag()
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of tags that this comment parser allows for it's comment.
|
||||
*
|
||||
* Each tag should indicate if only one entry of this tag can exist in the
|
||||
* comment by specifying true as the array value, or false if more than one
|
||||
* is allowed. Each tag should ommit the @ symbol. Only tags other than
|
||||
* the standard tags should be returned.
|
||||
*
|
||||
* @return array(string => boolean)
|
||||
*/
|
||||
protected abstract function getAllowedTags();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the tag orders (index => tagName).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTagOrders()
|
||||
{
|
||||
return $this->orders;
|
||||
|
||||
}//end getTagOrders()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the unknown tags.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUnknown()
|
||||
{
|
||||
return $this->unknown;
|
||||
|
||||
}//end getUnknown()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,341 @@
|
||||
<?php
|
||||
/**
|
||||
* Parses Class doc comments.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractParser', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractParser not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses Class doc comments.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_ClassCommentParser extends PHP_CodeSniffer_CommentParser_AbstractParser
|
||||
{
|
||||
|
||||
/**
|
||||
* The package element of this class.
|
||||
*
|
||||
* @var SingleElement
|
||||
*/
|
||||
private $_package = null;
|
||||
|
||||
/**
|
||||
* The subpackage element of this class.
|
||||
*
|
||||
* @var SingleElement
|
||||
*/
|
||||
private $_subpackage = null;
|
||||
|
||||
/**
|
||||
* The version element of this class.
|
||||
*
|
||||
* @var SingleElement
|
||||
*/
|
||||
private $_version = null;
|
||||
|
||||
/**
|
||||
* The category element of this class.
|
||||
*
|
||||
* @var SingleElement
|
||||
*/
|
||||
private $_category = null;
|
||||
|
||||
/**
|
||||
* The copyright elements of this class.
|
||||
*
|
||||
* @var array(SingleElement)
|
||||
*/
|
||||
private $_copyrights = array();
|
||||
|
||||
/**
|
||||
* The licence element of this class.
|
||||
*
|
||||
* @var PairElement
|
||||
*/
|
||||
private $_license = null;
|
||||
|
||||
/**
|
||||
* The author elements of this class.
|
||||
*
|
||||
* @var array(SingleElement)
|
||||
*/
|
||||
private $_authors = array();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the allowed tags withing a class comment.
|
||||
*
|
||||
* @return array(string => int)
|
||||
*/
|
||||
protected function getAllowedTags()
|
||||
{
|
||||
return array(
|
||||
'category' => false,
|
||||
'package' => true,
|
||||
'subpackage' => true,
|
||||
'author' => false,
|
||||
'copyright' => true,
|
||||
'license' => false,
|
||||
'version' => true,
|
||||
);
|
||||
|
||||
}//end getAllowedTags()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the license tag of this class comment.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this tag.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
protected function parseLicense($tokens)
|
||||
{
|
||||
$this->_license = new PHP_CodeSniffer_CommentParser_PairElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'license',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
return $this->_license;
|
||||
|
||||
}//end parseLicense()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the copyright tags of this class comment.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this tag.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parseCopyright($tokens)
|
||||
{
|
||||
$copyright = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'copyright',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
$this->_copyrights[] = $copyright;
|
||||
return $copyright;
|
||||
|
||||
}//end parseCopyright()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the category tag of this class comment.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this tag.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parseCategory($tokens)
|
||||
{
|
||||
$this->_category = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'category',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
return $this->_category;
|
||||
|
||||
}//end parseCategory()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the author tag of this class comment.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this tag.
|
||||
*
|
||||
* @return array(PHP_CodeSniffer_CommentParser_SingleElement)
|
||||
*/
|
||||
protected function parseAuthor($tokens)
|
||||
{
|
||||
$author = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'author',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
$this->_authors[] = $author;
|
||||
return $author;
|
||||
|
||||
}//end parseAuthor()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the version tag of this class comment.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this tag.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parseVersion($tokens)
|
||||
{
|
||||
$this->_version = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'version',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
return $this->_version;
|
||||
|
||||
}//end parseVersion()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the package tag found in this test.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this var.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parsePackage($tokens)
|
||||
{
|
||||
$this->_package = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'package',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
return $this->_package;
|
||||
|
||||
}//end parsePackage()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the package tag found in this test.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this var.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parseSubpackage($tokens)
|
||||
{
|
||||
$this->_subpackage = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'subpackage',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
return $this->_subpackage;
|
||||
|
||||
}//end parseSubpackage()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the authors of this class comment.
|
||||
*
|
||||
* @return array(PHP_CodeSniffer_CommentParser_SingleElement)
|
||||
*/
|
||||
public function getAuthors()
|
||||
{
|
||||
return $this->_authors;
|
||||
|
||||
}//end getAuthors()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the version of this class comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->_version;
|
||||
|
||||
}//end getVersion()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the license of this class comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
public function getLicense()
|
||||
{
|
||||
return $this->_license;
|
||||
|
||||
}//end getLicense()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the copyrights of this class comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
public function getCopyrights()
|
||||
{
|
||||
return $this->_copyrights;
|
||||
|
||||
}//end getCopyrights()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the category of this class comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->_category;
|
||||
|
||||
}//end getCategory()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the package that this class belongs to.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
public function getPackage()
|
||||
{
|
||||
return $this->_package;
|
||||
|
||||
}//end getPackage()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the subpackage that this class belongs to.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
public function getSubpackage()
|
||||
{
|
||||
return $this->_subpackage;
|
||||
|
||||
}//end getSubpackage()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to represent Comments of a doc comment.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_SingleElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_SingleElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to represent Comments of a doc comment.
|
||||
*
|
||||
* Comments are in the following format.
|
||||
* <code>
|
||||
* /** <--this is the start of the comment.
|
||||
* * This is a short comment description
|
||||
* *
|
||||
* * This is a long comment description
|
||||
* * <-- this is the end of the comment
|
||||
* * @return something
|
||||
* {@/}
|
||||
* </code>
|
||||
*
|
||||
* Note that the sentence before two newlines is assumed
|
||||
* the short comment description.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_CommentElement extends PHP_CodeSniffer_CommentParser_SingleElement
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PHP_CodeSniffer_CommentParser_CommentElement.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElemement $previousElement The element
|
||||
* that
|
||||
* appears
|
||||
* before this
|
||||
* element.
|
||||
* @param array $tokens The tokens
|
||||
* that make
|
||||
* up this
|
||||
* element.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file
|
||||
* that this
|
||||
* element is
|
||||
* in.
|
||||
*/
|
||||
public function __construct(
|
||||
$previousElement,
|
||||
$tokens,
|
||||
PHP_CodeSniffer_File $phpcsFile
|
||||
) {
|
||||
parent::__construct($previousElement, $tokens, 'comment', $phpcsFile);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the short comment description.
|
||||
*
|
||||
* @return string
|
||||
* @see getLongComment()
|
||||
*/
|
||||
public function getShortComment()
|
||||
{
|
||||
$pos = $this->_getShortCommentEndPos();
|
||||
if ($pos === -1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return implode('', array_slice($this->tokens, 0, ($pos + 1)));
|
||||
|
||||
}//end getShortComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the last token position of the short comment description.
|
||||
*
|
||||
* @return int The last token position of the short comment description
|
||||
* @see _getLongCommentStartPos()
|
||||
*/
|
||||
private function _getShortCommentEndPos()
|
||||
{
|
||||
$found = false;
|
||||
$whiteSpace = array(
|
||||
' ',
|
||||
"\t",
|
||||
);
|
||||
|
||||
foreach ($this->tokens as $pos => $token) {
|
||||
$token = str_replace($whiteSpace, '', $token);
|
||||
if ($token === $this->phpcsFile->eolChar) {
|
||||
if ($found === false) {
|
||||
// Include newlines before short description.
|
||||
continue;
|
||||
} else {
|
||||
if (isset($this->tokens[($pos + 1)]) === true) {
|
||||
if ($this->tokens[($pos + 1)] === $this->phpcsFile->eolChar) {
|
||||
return ($pos - 1);
|
||||
}
|
||||
} else {
|
||||
return $pos;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$found = true;
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
return (count($this->tokens) - 1);
|
||||
|
||||
}//end _getShortCommentEndPos()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the long comment description.
|
||||
*
|
||||
* @return string
|
||||
* @see getShortComment
|
||||
*/
|
||||
public function getLongComment()
|
||||
{
|
||||
$start = $this->_getLongCommentStartPos();
|
||||
if ($start === -1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return implode('', array_slice($this->tokens, $start));
|
||||
|
||||
}//end getLongComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the start position of the long comment description.
|
||||
*
|
||||
* Returns -1 if there is no long comment.
|
||||
*
|
||||
* @return int The start position of the long comment description.
|
||||
* @see _getShortCommentEndPos()
|
||||
*/
|
||||
private function _getLongCommentStartPos()
|
||||
{
|
||||
$pos = ($this->_getShortCommentEndPos() + 1);
|
||||
if ($pos === (count($this->tokens) - 1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
$count = count($this->tokens);
|
||||
for ($i = $pos; $i < $count; $i++) {
|
||||
$content = trim($this->tokens[$i]);
|
||||
if ($content !== '') {
|
||||
if ($content{0} === '@') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}//end _getLongCommentStartPos()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace that exists between
|
||||
* the short and the long comment description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWhiteSpaceBetween()
|
||||
{
|
||||
$endShort = ($this->_getShortCommentEndPos() + 1);
|
||||
$startLong = ($this->_getLongCommentStartPos() - 1);
|
||||
if ($startLong === -1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return implode(
|
||||
'',
|
||||
array_slice($this->tokens, $endShort, ($startLong - $endShort))
|
||||
);
|
||||
|
||||
}//end getWhiteSpaceBetween()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of newlines that exist before the tags.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNewlineAfter()
|
||||
{
|
||||
$long = $this->getLongComment();
|
||||
if ($long !== '') {
|
||||
$long = rtrim($long, ' ');
|
||||
$long = strrev($long);
|
||||
$newlines = strspn($long, $this->phpcsFile->eolChar);
|
||||
} else {
|
||||
$endShort = ($this->_getShortCommentEndPos() + 1);
|
||||
$after = implode('', array_slice($this->tokens, $endShort));
|
||||
$after = trim($after, ' ');
|
||||
$newlines = strspn($after, $this->phpcsFile->eolChar);
|
||||
}
|
||||
|
||||
return ($newlines / strlen($this->phpcsFile->eolChar));
|
||||
|
||||
}//end getNewlineAfter()
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if there is no comment.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return (trim($this->getContent()) === '');
|
||||
|
||||
}//end isEmpty()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
104
database/php/pear/PHP/CodeSniffer/CommentParser/DocElement.php
Normal file
104
database/php/pear/PHP/CodeSniffer/CommentParser/DocElement.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* A DocElement represents a logical element within a Doc Comment.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* A DocElement represents a logical element within a Doc Comment.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
interface PHP_CodeSniffer_CommentParser_DocElement
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the tag this element represents, omitting the @ symbol.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTag();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace that exists before this element.
|
||||
*
|
||||
* @return string
|
||||
* @see getWhitespaceAfter()
|
||||
*/
|
||||
public function getWhitespaceBefore();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace that exists after this element.
|
||||
*
|
||||
* @return string
|
||||
* @see getWhitespaceBefore()
|
||||
*/
|
||||
public function getWhitespaceAfter();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the order that this element appears in the doc comment.
|
||||
*
|
||||
* The first element in the comment should have an order of 1.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOrder();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element that appears before this element.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_DocElement
|
||||
* @see getNextElement()
|
||||
*/
|
||||
public function getPreviousElement();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element that appears after this element.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_DocElement
|
||||
* @see getPreviousElement()
|
||||
*/
|
||||
public function getNextElement();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the line that this element started on.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLine();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the raw content of this element, ommiting the tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawContent();
|
||||
|
||||
|
||||
}//end interface
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
/**
|
||||
* Parses function doc comments.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractParser', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractParser not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_ParameterElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_ParameterElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_PairElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_PairElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_SingleElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_SingleElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses function doc comments.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_FunctionCommentParser extends PHP_CodeSniffer_CommentParser_AbstractParser
|
||||
{
|
||||
|
||||
/**
|
||||
* The parameter elements within this function comment.
|
||||
*
|
||||
* @var array(PHP_CodeSniffer_CommentParser_ParameterElement)
|
||||
*/
|
||||
private $_params = array();
|
||||
|
||||
/**
|
||||
* The return element in this function comment.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_PairElement.
|
||||
*/
|
||||
private $_return = null;
|
||||
|
||||
/**
|
||||
* The throws element list for this function comment.
|
||||
*
|
||||
* @var array(PHP_CodeSniffer_CommentParser_PairElement)
|
||||
*/
|
||||
private $_throws = array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PHP_CodeSniffer_CommentParser_FunctionCommentParser.
|
||||
*
|
||||
* @param string $comment The comment to parse.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that this comment is in.
|
||||
*/
|
||||
public function __construct($comment, PHP_CodeSniffer_File $phpcsFile)
|
||||
{
|
||||
parent::__construct($comment, $phpcsFile);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Parses parameter elements.
|
||||
*
|
||||
* @param array(string) $tokens The tokens that conmpise this sub element.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_ParameterElement
|
||||
*/
|
||||
protected function parseParam($tokens)
|
||||
{
|
||||
$param = new PHP_CodeSniffer_CommentParser_ParameterElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
$this->_params[] = $param;
|
||||
return $param;
|
||||
|
||||
}//end parseParam()
|
||||
|
||||
|
||||
/**
|
||||
* Parses return elements.
|
||||
*
|
||||
* @param array(string) $tokens The tokens that conmpise this sub element.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
protected function parseReturn($tokens)
|
||||
{
|
||||
$return = new PHP_CodeSniffer_CommentParser_PairElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'return',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
$this->_return = $return;
|
||||
return $return;
|
||||
|
||||
}//end parseReturn()
|
||||
|
||||
|
||||
/**
|
||||
* Parses throws elements.
|
||||
*
|
||||
* @param array(string) $tokens The tokens that conmpise this sub element.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
protected function parseThrows($tokens)
|
||||
{
|
||||
$throws = new PHP_CodeSniffer_CommentParser_PairElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'throws',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
$this->_throws[] = $throws;
|
||||
return $throws;
|
||||
|
||||
}//end parseThrows()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the parameter elements that this function comment contains.
|
||||
*
|
||||
* Returns an empty array if no parameter elements are contained within
|
||||
* this function comment.
|
||||
*
|
||||
* @return array(PHP_CodeSniffer_CommentParser_ParameterElement)
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->_params;
|
||||
|
||||
}//end getParams()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the return element in this fucntion comment.
|
||||
*
|
||||
* Returns null if no return element exists in the comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
public function getReturn()
|
||||
{
|
||||
return $this->_return;
|
||||
|
||||
}//end getReturn()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the throws elements in this fucntion comment.
|
||||
*
|
||||
* Returns empty array if no throws elements in the comment.
|
||||
*
|
||||
* @return array(PHP_CodeSniffer_CommentParser_PairElement)
|
||||
*/
|
||||
public function getThrows()
|
||||
{
|
||||
return $this->_throws;
|
||||
|
||||
}//end getThrows()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the allowed tags that can exist in a function comment.
|
||||
*
|
||||
* @return array(string => boolean)
|
||||
*/
|
||||
protected function getAllowedTags()
|
||||
{
|
||||
return array(
|
||||
'param' => false,
|
||||
'return' => true,
|
||||
'throws' => false,
|
||||
);
|
||||
|
||||
}//end getAllowedTags()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Parses class member comments.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses class member comments.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_MemberCommentParser extends PHP_CodeSniffer_CommentParser_ClassCommentParser
|
||||
{
|
||||
|
||||
/**
|
||||
* Represents a \@var tag in a member comment.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
private $_var = null;
|
||||
|
||||
|
||||
/**
|
||||
* Parses Var tags.
|
||||
*
|
||||
* @param array $tokens The tokens that represent this tag.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parseVar($tokens)
|
||||
{
|
||||
$this->_var = new PHP_CodeSniffer_CommentParser_SingleElement(
|
||||
$this->previousElement,
|
||||
$tokens,
|
||||
'var',
|
||||
$this->phpcsFile
|
||||
);
|
||||
|
||||
return $this->_var;
|
||||
|
||||
}//end parseVar()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the var tag found in the member comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
public function getVar()
|
||||
{
|
||||
return $this->_var;
|
||||
|
||||
}//end getVar()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the allowed tags for this parser.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllowedTags()
|
||||
{
|
||||
return array('var' => true);
|
||||
|
||||
}//end getAllowedTags()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
171
database/php/pear/PHP/CodeSniffer/CommentParser/PairElement.php
Normal file
171
database/php/pear/PHP/CodeSniffer/CommentParser/PairElement.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to represent elements that have a value => comment format.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to represent elements that have a value => comment format.
|
||||
*
|
||||
* An example of a pair element tag is the \@throws as it has an exception type
|
||||
* and a comment on the circumstance of when the exception is thrown.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_PairElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
|
||||
{
|
||||
|
||||
/**
|
||||
* The value of the tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_value = '';
|
||||
|
||||
/**
|
||||
* The comment of the tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_comment = '';
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the value elem.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_valueWhitespace = '';
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the comment elem.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_commentWhitespace = '';
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PHP_CodeSniffer_CommentParser_PairElement doc tag.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
|
||||
* before this
|
||||
* one.
|
||||
* @param array $tokens The tokens
|
||||
* that comprise
|
||||
* this element.
|
||||
* @param string $tag The tag that
|
||||
* this element
|
||||
* represents.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that
|
||||
* this element
|
||||
* is in.
|
||||
*/
|
||||
public function __construct(
|
||||
$previousElement,
|
||||
$tokens,
|
||||
$tag,
|
||||
PHP_CodeSniffer_File $phpcsFile
|
||||
) {
|
||||
parent::__construct($previousElement, $tokens, $tag, $phpcsFile);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element names that this tag is comprised of, in the order
|
||||
* that they appear in the tag.
|
||||
*
|
||||
* @return array(string)
|
||||
* @see processSubElement()
|
||||
*/
|
||||
protected function getSubElements()
|
||||
{
|
||||
return array(
|
||||
'value',
|
||||
'comment',
|
||||
);
|
||||
|
||||
}//end getSubElements()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the sub element with the specified name.
|
||||
*
|
||||
* @param string $name The name of the sub element to process.
|
||||
* @param string $content The content of this sub element.
|
||||
* @param string $whitespaceBefore The whitespace that exists before the
|
||||
* sub element.
|
||||
*
|
||||
* @return void
|
||||
* @see getSubElements()
|
||||
*/
|
||||
protected function processSubElement($name, $content, $whitespaceBefore)
|
||||
{
|
||||
$element = '_'.$name;
|
||||
$whitespace = $element.'Whitespace';
|
||||
$this->$element = $content;
|
||||
$this->$whitespace = $whitespaceBefore;
|
||||
|
||||
}//end processSubElement()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of the tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
|
||||
}//end getValue()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the comment associated with the value of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->_comment;
|
||||
|
||||
}//end getComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the witespace before the content of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWhitespaceBeforeValue()
|
||||
{
|
||||
return $this->_valueWhitespace;
|
||||
|
||||
}//end getWhitespaceBeforeValue()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,334 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to represent param tags within a function comment.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to represent param tags within a function comment.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_ParameterElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
|
||||
{
|
||||
|
||||
/**
|
||||
* The variable name of this parameter name, including the $ sign.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_varName = '';
|
||||
|
||||
/**
|
||||
* The comment of this parameter tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_comment = '';
|
||||
|
||||
/**
|
||||
* The variable type of this parameter tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_type = '';
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the variable name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_varNameWhitespace = '';
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the comment.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_commentWhitespace = null;
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the variable type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_typeWhitespace = '';
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PHP_CodeSniffer_CommentParser_ParameterElement.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
|
||||
* previous to
|
||||
* this one.
|
||||
* @param array $tokens The tokens
|
||||
* that make up
|
||||
* this element.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that
|
||||
* this element
|
||||
* is in.
|
||||
*/
|
||||
public function __construct(
|
||||
$previousElement,
|
||||
$tokens,
|
||||
PHP_CodeSniffer_File $phpcsFile
|
||||
) {
|
||||
parent::__construct($previousElement, $tokens, 'param', $phpcsFile);
|
||||
|
||||
// Handle special variable type: array(x => y).
|
||||
$type = strtolower($this->_type);
|
||||
if ($this->_varName === '=>' && strpos($type, 'array(') !== false) {
|
||||
$rawContent = $this->getRawContent();
|
||||
$matches = array();
|
||||
$pattern = '/^(\s+)(array\(.*\))(\s+)(\$\S*)(\s+)(.*)/i';
|
||||
if (preg_match($pattern, $rawContent, $matches) !== 0) {
|
||||
// Process the sub elements correctly for this special case.
|
||||
if (count($matches) === 7) {
|
||||
$this->processSubElement('type', $matches[2], $matches[1]);
|
||||
$this->processSubElement('varName', $matches[4], $matches[3]);
|
||||
$this->processSubElement('comment', $matches[6], $matches[5]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element names that this tag is comprised of, in the order
|
||||
* that they appear in the tag.
|
||||
*
|
||||
* @return array(string)
|
||||
* @see processSubElement()
|
||||
*/
|
||||
protected function getSubElements()
|
||||
{
|
||||
return array(
|
||||
'type',
|
||||
'varName',
|
||||
'comment',
|
||||
);
|
||||
|
||||
}//end getSubElements()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the sub element with the specified name.
|
||||
*
|
||||
* @param string $name The name of the sub element to process.
|
||||
* @param string $content The content of this sub element.
|
||||
* @param string $beforeWhitespace The whitespace that exists before the
|
||||
* sub element.
|
||||
*
|
||||
* @return void
|
||||
* @see getSubElements()
|
||||
*/
|
||||
protected function processSubElement($name, $content, $beforeWhitespace)
|
||||
{
|
||||
$element = '_'.$name;
|
||||
$whitespace = $element.'Whitespace';
|
||||
$this->$element = $content;
|
||||
$this->$whitespace = $beforeWhitespace;
|
||||
|
||||
}//end processSubElement()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the variable name that this parameter tag represents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVarName()
|
||||
{
|
||||
return $this->_varName;
|
||||
|
||||
}//end getVarName()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the variable type that this string represents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
|
||||
}//end getType()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the comment of this comment for this parameter.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->_comment;
|
||||
|
||||
}//end getComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace before the variable type.
|
||||
*
|
||||
* @return stirng
|
||||
* @see getWhiteSpaceBeforeVarName()
|
||||
* @see getWhiteSpaceBeforeComment()
|
||||
*/
|
||||
public function getWhiteSpaceBeforeType()
|
||||
{
|
||||
return $this->_typeWhitespace;
|
||||
|
||||
}//end getWhiteSpaceBeforeType()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace before the variable name.
|
||||
*
|
||||
* @return string
|
||||
* @see getWhiteSpaceBeforeComment()
|
||||
* @see getWhiteSpaceBeforeType()
|
||||
*/
|
||||
public function getWhiteSpaceBeforeVarName()
|
||||
{
|
||||
return $this->_varNameWhitespace;
|
||||
|
||||
}//end getWhiteSpaceBeforeVarName()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace before the comment.
|
||||
*
|
||||
* @return string
|
||||
* @see getWhiteSpaceBeforeVarName()
|
||||
* @see getWhiteSpaceBeforeType()
|
||||
*/
|
||||
public function getWhiteSpaceBeforeComment()
|
||||
{
|
||||
return $this->_commentWhitespace;
|
||||
|
||||
}//end getWhiteSpaceBeforeComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the postition of this parameter are it appears in the comment.
|
||||
*
|
||||
* This method differs from getOrder as it is only relative to method
|
||||
* parameters.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
if (($this->getPreviousElement() instanceof PHP_CodeSniffer_CommentParser_ParameterElement) === false) {
|
||||
return 1;
|
||||
} else {
|
||||
return ($this->getPreviousElement()->getPosition() + 1);
|
||||
}
|
||||
|
||||
}//end getPosition()
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this parameter's variable aligns with the other's.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_ParameterElement $other The other param
|
||||
* to check
|
||||
* alignment with.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function alignsVariableWith(
|
||||
PHP_CodeSniffer_CommentParser_ParameterElement $other
|
||||
) {
|
||||
// Format is:
|
||||
// @param type $variable Comment.
|
||||
// @param <-a-><---b---->
|
||||
// Compares the index before param variable.
|
||||
$otherVar = (strlen($other->_type) + strlen($other->_varNameWhitespace));
|
||||
$thisVar = (strlen($this->_type) + strlen($this->_varNameWhitespace));
|
||||
if ($otherVar !== $thisVar) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end alignsVariableWith()
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this parameter's comment aligns with the other's.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_ParameterElement $other The other param
|
||||
* to check
|
||||
* alignment with.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function alignsCommentWith(
|
||||
PHP_CodeSniffer_CommentParser_ParameterElement $other
|
||||
) {
|
||||
// Compares the index before param comment.
|
||||
$otherComment
|
||||
= (strlen($other->_varName) + strlen($other->_commentWhitespace));
|
||||
$thisComment
|
||||
= (strlen($this->_varName) + strlen($this->_commentWhitespace));
|
||||
|
||||
if ($otherComment !== $thisComment) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end alignsCommentWith()
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this parameter aligns with the other paramter.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_ParameterElement $other The other param
|
||||
* to check
|
||||
* alignment with.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function alignsWith(PHP_CodeSniffer_CommentParser_ParameterElement $other)
|
||||
{
|
||||
if ($this->alignsVariableWith($other) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->alignsCommentWith($other) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end alignsWith()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* An exception to be thrown when a DocCommentParser finds an anomilty in a
|
||||
* doc comment.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* An exception to be thrown when a DocCommentParser finds an anomilty in a
|
||||
* doc comment.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_ParserException extends Exception
|
||||
{
|
||||
|
||||
/**
|
||||
* The line where the exception occured, in relation to the doc comment.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_line = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a DocCommentParserException.
|
||||
*
|
||||
* @param string $message The message of the exception.
|
||||
* @param int $line The position in comment where the error occured.
|
||||
* A position of 0 indicates that the error occured
|
||||
* at the opening line of the doc comment.
|
||||
*/
|
||||
public function __construct($message, $line)
|
||||
{
|
||||
parent::__construct($message);
|
||||
$this->_line = $line;
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the line number within the comment where the exception occured.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLineWithinComment()
|
||||
{
|
||||
return $this->_line;
|
||||
|
||||
}//end getLineWithinComment()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to represent single element doc tags.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to represent single element doc tags.
|
||||
*
|
||||
* A single element doc tag contains only one value after the tag itself. An
|
||||
* example would be the \@package tag.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_SingleElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
|
||||
{
|
||||
|
||||
/**
|
||||
* The content that exists after the tag.
|
||||
*
|
||||
* @var string
|
||||
* @see getContent()
|
||||
*/
|
||||
protected $content = '';
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the content.
|
||||
*
|
||||
* @var string
|
||||
* @see getWhitespaceBeforeContent()
|
||||
*/
|
||||
protected $contentWhitespace = '';
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a SingleElement doc tag.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
|
||||
* before this
|
||||
* one.
|
||||
* @param array $tokens The tokens
|
||||
* that comprise
|
||||
* this element.
|
||||
* @param string $tag The tag that
|
||||
* this element
|
||||
* represents.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that
|
||||
* this element
|
||||
* is in.
|
||||
*/
|
||||
public function __construct(
|
||||
$previousElement,
|
||||
$tokens,
|
||||
$tag,
|
||||
PHP_CodeSniffer_File $phpcsFile
|
||||
) {
|
||||
parent::__construct($previousElement, $tokens, $tag, $phpcsFile);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element names that this tag is comprised of, in the order
|
||||
* that they appear in the tag.
|
||||
*
|
||||
* @return array(string)
|
||||
* @see processSubElement()
|
||||
*/
|
||||
protected function getSubElements()
|
||||
{
|
||||
return array('content');
|
||||
|
||||
}//end getSubElements()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the sub element with the specified name.
|
||||
*
|
||||
* @param string $name The name of the sub element to process.
|
||||
* @param string $content The content of this sub element.
|
||||
* @param string $whitespaceBefore The whitespace that exists before the
|
||||
* sub element.
|
||||
*
|
||||
* @return void
|
||||
* @see getSubElements()
|
||||
*/
|
||||
protected function processSubElement($name, $content, $whitespaceBefore)
|
||||
{
|
||||
$this->content = $content;
|
||||
$this->contentWhitespace = $whitespaceBefore;
|
||||
|
||||
}//end processSubElement()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the content of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
|
||||
}//end getContent()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the witespace before the content of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWhitespaceBeforeContent()
|
||||
{
|
||||
return $this->contentWhitespace;
|
||||
|
||||
}//end getWhitespaceBeforeContent()
|
||||
|
||||
|
||||
/**
|
||||
* Processes a content check for single doc element.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $commentStart The line number where
|
||||
* the error occurs.
|
||||
* @param string $docBlock Whether this is a file or
|
||||
* class comment doc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(
|
||||
PHP_CodeSniffer_File $phpcsFile,
|
||||
$commentStart,
|
||||
$docBlock
|
||||
) {
|
||||
if ($this->content === '') {
|
||||
$errorPos = ($commentStart + $this->getLine());
|
||||
$error = 'Content missing for %s tag in %s comment';
|
||||
$data = array(
|
||||
$this->tag,
|
||||
$docBlock,
|
||||
);
|
||||
$phpcsFile->addError($error, $errorPos, 'EmptyTagContent', $data);
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user