| @@ -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,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 | ||
|
|
||
| ?> |
| @@ -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 | ||
|
|
||
| ?> |
| @@ -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 | ||
|
|
||
| ?> |
| @@ -0,0 +1,197 @@ | ||
| <?php | ||
| /** | ||
| * The base class for all PHP_CodeSniffer documentation generators. | ||
| * | ||
| * 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 | ||
| */ | ||
|
|
||
| /** | ||
| * The base class for all PHP_CodeSniffer documentation generators. | ||
| * | ||
| * Documentation generators are used to print documentation about code sniffs | ||
| * in a standard. | ||
| * | ||
| * @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_DocGenerators_Generator | ||
| { | ||
|
|
||
| /** | ||
| * The name of the coding standard we are generating docs for. | ||
| * | ||
| * @var string | ||
| */ | ||
| private $_standard = ''; | ||
|
|
||
| /** | ||
| * An array of sniffs that we are limiting the generated docs to. | ||
| * | ||
| * If this array is empty, docs are generated for all sniffs in the | ||
| * supplied coding standard. | ||
| * | ||
| * @var string | ||
| */ | ||
| private $_sniffs = array(); | ||
|
|
||
|
|
||
| /** | ||
| * Constructs a PHP_CodeSniffer_DocGenerators_Generator object. | ||
| * | ||
| * @param string $standard The name of the coding standard to generate | ||
| * docs for. | ||
| * @param array $sniffs An array of sniffs that we are limiting the | ||
| * generated docs to. | ||
| * | ||
| * @see generate() | ||
| */ | ||
| public function __construct($standard, array $sniffs=array()) | ||
| { | ||
| $this->_standard = $standard; | ||
| $this->_sniffs = $sniffs; | ||
|
|
||
| }//end __construct() | ||
|
|
||
|
|
||
| /** | ||
| * Retrieves the title of the sniff from the DOMNode supplied. | ||
| * | ||
| * @param DOMNode $doc The DOMNode object for the sniff. | ||
| * It represents the "documentation" tag in the XML | ||
| * standard file. | ||
| * | ||
| * @return string | ||
| */ | ||
| protected function getTitle(DOMNode $doc) | ||
| { | ||
| return $doc->getAttribute('title'); | ||
|
|
||
| }//end getTitle() | ||
|
|
||
|
|
||
| /** | ||
| * Retrieves the name of the standard we are generating docs for. | ||
| * | ||
| * @return string | ||
| */ | ||
| protected function getStandard() | ||
| { | ||
| return $this->_standard; | ||
|
|
||
| }//end getStandard() | ||
|
|
||
|
|
||
| /** | ||
| * Generates the documentation for a standard. | ||
| * | ||
| * It's probably wise for doc generators to override this method so they | ||
| * have control over how the docs are produced. Otherwise, the processSniff | ||
| * method should be overridden to output content for each sniff. | ||
| * | ||
| * @return void | ||
| * @see processSniff() | ||
| */ | ||
| public function generate() | ||
| { | ||
| $standardFiles = $this->getStandardFiles(); | ||
|
|
||
| foreach ($standardFiles as $standard) { | ||
| $doc = new DOMDocument(); | ||
| $doc->load($standard); | ||
| $documentation = $doc->getElementsByTagName('documentation')->item(0); | ||
| $this->processSniff($documentation); | ||
| } | ||
|
|
||
| }//end generate() | ||
|
|
||
|
|
||
| /** | ||
| * Returns a list of paths to XML standard files for all sniffs in a standard. | ||
| * | ||
| * Any sniffs that do not have an XML standard file are obviously not included | ||
| * in the returned array. If documentation is only being generated for some | ||
| * sniffs (ie. $this->_sniffs is not empty) then all others sniffs will | ||
| * be filtered from the results as well. | ||
| * | ||
| * @return array(string) | ||
| */ | ||
| protected function getStandardFiles() | ||
| { | ||
| if (is_dir($this->_standard) === true) { | ||
| // This is a custom standard. | ||
| $standardDir = $this->_standard; | ||
| $standard = basename($this->_standard); | ||
| } else { | ||
| $standardDir | ||
| = realpath(dirname(__FILE__).'/../Standards/'.$this->_standard); | ||
|
|
||
| $standard = $this->_standard; | ||
| } | ||
|
|
||
| $phpcs = new PHP_CodeSniffer(); | ||
| $sniffs = $phpcs->getSniffFiles($standardDir, $standard); | ||
|
|
||
| $standardFiles = array(); | ||
| foreach ($sniffs as $sniff) { | ||
| if (empty($this->_sniffs) === false) { | ||
| // We are limiting the docs to certain sniffs only, so filter | ||
| // out any unwanted sniffs. | ||
| $sniffName = substr($sniff, (strrpos($sniff, '/') + 1)); | ||
| $sniffName = substr($sniffName, 0, -9); | ||
| if (in_array($sniffName, $this->_sniffs) === false) { | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| $standardFile = str_replace( | ||
| DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR, | ||
| DIRECTORY_SEPARATOR.'Docs'.DIRECTORY_SEPARATOR, | ||
| $sniff | ||
| ); | ||
| $standardFile = str_replace('Sniff.php', 'Standard.xml', $standardFile); | ||
|
|
||
| if (is_file($standardFile) === true) { | ||
| $standardFiles[] = $standardFile; | ||
| } | ||
| }//end foreach | ||
|
|
||
| return $standardFiles; | ||
|
|
||
| }//end getStandardFiles() | ||
|
|
||
|
|
||
| /** | ||
| * Process the documentation for a single sniff. | ||
| * | ||
| * Doc generators should override this function to produce output. | ||
| * | ||
| * @param DOMNode $doc The DOMNode object for the sniff. | ||
| * It represents the "documentation" tag in the XML | ||
| * standard file. | ||
| * | ||
| * @return void | ||
| * @see generate() | ||
| */ | ||
| protected function processSniff(DOMNode $doc) | ||
| { | ||
|
|
||
| }//end processSniff() | ||
|
|
||
|
|
||
| }//end class | ||
|
|
||
| ?> |
| @@ -0,0 +1,292 @@ | ||
| <?php | ||
| /** | ||
| * A doc generator that outputs documentation in one big HTML file. | ||
| * | ||
| * 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_DocGenerators_Generator', true) === false) { | ||
| throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_DocGenerators_Generator not found'); | ||
| } | ||
|
|
||
| /** | ||
| * A doc generator that outputs documentation in one big HTML file. | ||
| * | ||
| * Output is in one large HTML file and is designed for you to style with | ||
| * your own stylesheet. It contains a table of contents at the top with anchors | ||
| * to each sniff. | ||
| * | ||
| * @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_DocGenerators_HTML extends PHP_CodeSniffer_DocGenerators_Generator | ||
| { | ||
|
|
||
|
|
||
| /** | ||
| * Generates the documentation for a standard. | ||
| * | ||
| * @return void | ||
| * @see processSniff() | ||
| */ | ||
| public function generate() | ||
| { | ||
| ob_start(); | ||
| $this->printHeader(); | ||
|
|
||
| $standardFiles = $this->getStandardFiles(); | ||
| $this->printToc($standardFiles); | ||
|
|
||
| foreach ($standardFiles as $standard) { | ||
| $doc = new DOMDocument(); | ||
| $doc->load($standard); | ||
| $documentation = $doc->getElementsByTagName('documentation')->item(0); | ||
| $this->processSniff($documentation); | ||
| } | ||
|
|
||
| $this->printFooter(); | ||
|
|
||
| $content = ob_get_contents(); | ||
| ob_end_clean(); | ||
|
|
||
| echo $content; | ||
|
|
||
| }//end generate() | ||
|
|
||
|
|
||
| /** | ||
| * Print the header of the HTML page. | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function printHeader() | ||
| { | ||
| $standard = $this->getStandard(); | ||
| echo '<html>'.PHP_EOL; | ||
| echo ' <head>'.PHP_EOL; | ||
| echo " <title>$standard Coding Standards</title>".PHP_EOL; | ||
| echo ' <style> | ||
| body { | ||
| background-color: #FFFFFF; | ||
| font-size: 14px; | ||
| font-family: Arial, Helvetica, sans-serif; | ||
| color: #000000; | ||
| } | ||
| h1 { | ||
| color: #666666; | ||
| font-size: 20px; | ||
| font-weight: bold; | ||
| margin-top: 0px; | ||
| background-color: #E6E7E8; | ||
| padding: 20px; | ||
| border: 1px solid #BBBBBB; | ||
| } | ||
| h2 { | ||
| color: #00A5E3; | ||
| font-size: 16px; | ||
| font-weight: normal; | ||
| margin-top: 50px; | ||
| } | ||
| .code-comparison { | ||
| width: 100%; | ||
| } | ||
| .code-comparison td { | ||
| border: 1px solid #CCCCCC; | ||
| } | ||
| .code-comparison-title, .code-comparison-code { | ||
| font-family: Arial, Helvetica, sans-serif; | ||
| font-size: 12px; | ||
| color: #000000; | ||
| vertical-align: top; | ||
| padding: 4px; | ||
| width: 50%; | ||
| background-color: #F1F1F1; | ||
| line-height: 15px; | ||
| } | ||
| .code-comparison-code { | ||
| font-family: Courier; | ||
| background-color: #F9F9F9; | ||
| } | ||
| .code-comparison-highlight { | ||
| background-color: #DDF1F7; | ||
| border: 1px solid #00A5E3; | ||
| line-height: 15px; | ||
| } | ||
| .tag-line { | ||
| text-align: center; | ||
| width: 100%; | ||
| margin-top: 30px; | ||
| font-size: 12px; | ||
| } | ||
| .tag-line a { | ||
| color: #000000; | ||
| } | ||
| </style>'.PHP_EOL; | ||
| echo ' </head>'.PHP_EOL; | ||
| echo ' <body>'.PHP_EOL; | ||
| echo " <h1>$standard Coding Standards</h1>".PHP_EOL; | ||
|
|
||
| }//end printHeader() | ||
|
|
||
|
|
||
| /** | ||
| * Print the table of contents for the standard. | ||
| * | ||
| * The TOC is just an unordered list of bookmarks to sniffs on the page. | ||
| * | ||
| * @param array $standardFiles An array of paths to the XML standard files. | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function printToc($standardFiles) | ||
| { | ||
| echo ' <h2>Table of Contents</h2>'.PHP_EOL; | ||
| echo ' <ul class="toc">'.PHP_EOL; | ||
|
|
||
| foreach ($standardFiles as $standard) { | ||
| $doc = new DOMDocument(); | ||
| $doc->load($standard); | ||
| $documentation = $doc->getElementsByTagName('documentation')->item(0); | ||
| $title = $this->getTitle($documentation); | ||
| echo ' <li><a href="#'.str_replace(' ', '-', $title)."\">$title</a></li>".PHP_EOL; | ||
| } | ||
|
|
||
| echo ' </ul>'.PHP_EOL; | ||
|
|
||
| }//end printToc() | ||
|
|
||
|
|
||
| /** | ||
| * Print the footer of the HTML page. | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function printFooter() | ||
| { | ||
| // Turn off strict errors so we don't get timezone warnings if people | ||
| // don't have their timezone set. | ||
| error_reporting(E_ALL); | ||
| echo ' <div class="tag-line">'; | ||
| echo 'Documentation generated on '.date('r'); | ||
| echo ' by <a href="http://pear.php.net/package/PHP_CodeSniffer">PHP_CodeSniffer 1.3.3</a>'; | ||
| echo '</div>'.PHP_EOL; | ||
| error_reporting(E_ALL | E_STRICT); | ||
|
|
||
| echo ' </body>'.PHP_EOL; | ||
| echo '</html>'.PHP_EOL; | ||
|
|
||
| }//end printFooter() | ||
|
|
||
|
|
||
| /** | ||
| * Process the documentation for a single sniff. | ||
| * | ||
| * @param DOMNode $doc The DOMNode object for the sniff. | ||
| * It represents the "documentation" tag in the XML | ||
| * standard file. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function processSniff(DOMNode $doc) | ||
| { | ||
| $title = $this->getTitle($doc); | ||
| echo ' <a name="'.str_replace(' ', '-', $title).'" />'.PHP_EOL; | ||
| echo " <h2>$title</h2>".PHP_EOL; | ||
|
|
||
| foreach ($doc->childNodes as $node) { | ||
| if ($node->nodeName === 'standard') { | ||
| $this->printTextBlock($node); | ||
| } else if ($node->nodeName === 'code_comparison') { | ||
| $this->printCodeComparisonBlock($node); | ||
| } | ||
| } | ||
|
|
||
| }//end processSniff() | ||
|
|
||
|
|
||
| /** | ||
| * Print a text block found in a standard. | ||
| * | ||
| * @param DOMNode $node The DOMNode object for the text block. | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function printTextBlock($node) | ||
| { | ||
| $content = trim($node->nodeValue); | ||
| $content = htmlspecialchars($content); | ||
|
|
||
| // Allow em tags only. | ||
| $content = str_replace('<em>', '<em>', $content); | ||
| $content = str_replace('</em>', '</em>', $content); | ||
|
|
||
| echo " <p class=\"text\">$content</p>".PHP_EOL; | ||
|
|
||
| }//end printTextBlock() | ||
|
|
||
|
|
||
| /** | ||
| * Print a code comparison block found in a standard. | ||
| * | ||
| * @param DOMNode $node The DOMNode object for the code comparison block. | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function printCodeComparisonBlock($node) | ||
| { | ||
| $codeBlocks = $node->getElementsByTagName('code'); | ||
|
|
||
| $firstTitle = $codeBlocks->item(0)->getAttribute('title'); | ||
| $first = trim($codeBlocks->item(0)->nodeValue); | ||
| $first = str_replace("\n", '</br>', $first); | ||
| $first = str_replace(' ', ' ', $first); | ||
| $first = str_replace('<em>', '<span class="code-comparison-highlight">', $first); | ||
| $first = str_replace('</em>', '</span>', $first); | ||
|
|
||
| $secondTitle = $codeBlocks->item(1)->getAttribute('title'); | ||
| $second = trim($codeBlocks->item(1)->nodeValue); | ||
| $second = str_replace("\n", '</br>', $second); | ||
| $second = str_replace(' ', ' ', $second); | ||
| $second = str_replace('<em>', '<span class="code-comparison-highlight">', $second); | ||
| $second = str_replace('</em>', '</span>', $second); | ||
|
|
||
| echo ' <table class="code-comparison">'.PHP_EOL; | ||
| echo ' <tr>'.PHP_EOL; | ||
| echo " <td class=\"code-comparison-title\">$firstTitle</td>".PHP_EOL; | ||
| echo " <td class=\"code-comparison-title\">$secondTitle</td>".PHP_EOL; | ||
| echo ' </tr>'.PHP_EOL; | ||
| echo ' <tr>'.PHP_EOL; | ||
| echo " <td class=\"code-comparison-code\">$first</td>".PHP_EOL; | ||
| echo " <td class=\"code-comparison-code\">$second</td>".PHP_EOL; | ||
| echo ' </tr>'.PHP_EOL; | ||
| echo ' </table>'.PHP_EOL; | ||
|
|
||
| }//end printCodeComparisonBlock() | ||
|
|
||
|
|
||
| }//end class | ||
|
|
||
| ?> |
| @@ -0,0 +1,267 @@ | ||
| <?php | ||
| /** | ||
| * A doc generator that outputs text-based documentation. | ||
| * | ||
| * 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_DocGenerators_Generator', true) === false) { | ||
| throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_DocGenerators_Generator not found'); | ||
| } | ||
|
|
||
| /** | ||
| * A doc generator that outputs text-based documentation. | ||
| * | ||
| * Output is designed to be displayed in a terminal and is wrapped to 100 characters. | ||
| * | ||
| * @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_DocGenerators_Text extends PHP_CodeSniffer_DocGenerators_Generator | ||
| { | ||
|
|
||
|
|
||
| /** | ||
| * Process the documentation for a single sniff. | ||
| * | ||
| * @param DOMNode $doc The DOMNode object for the sniff. | ||
| * It represents the "documentation" tag in the XML | ||
| * standard file. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function processSniff(DOMNode $doc) | ||
| { | ||
| $this->printTitle($doc); | ||
|
|
||
| foreach ($doc->childNodes as $node) { | ||
| if ($node->nodeName === 'standard') { | ||
| $this->printTextBlock($node); | ||
| } else if ($node->nodeName === 'code_comparison') { | ||
| $this->printCodeComparisonBlock($node); | ||
| } | ||
| } | ||
|
|
||
| }//end processSniff() | ||
|
|
||
|
|
||
| /** | ||
| * Prints the title area for a single sniff. | ||
| * | ||
| * @param DOMNode $doc The DOMNode object for the sniff. | ||
| * It represents the "documentation" tag in the XML | ||
| * standard file. | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function printTitle(DOMNode $doc) | ||
| { | ||
| $title = $this->getTitle($doc); | ||
| $standard = $this->getStandard(); | ||
|
|
||
| echo PHP_EOL; | ||
| echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4)); | ||
| echo strtoupper(PHP_EOL."| $standard CODING STANDARD: $title |".PHP_EOL); | ||
| echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4)); | ||
| echo PHP_EOL.PHP_EOL; | ||
|
|
||
| }//end printTitle() | ||
|
|
||
|
|
||
| /** | ||
| * Print a text block found in a standard. | ||
| * | ||
| * @param DOMNode $node The DOMNode object for the text block. | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function printTextBlock($node) | ||
| { | ||
| $text = trim($node->nodeValue); | ||
| $text = str_replace('<em>', '*', $text); | ||
| $text = str_replace('</em>', '*', $text); | ||
|
|
||
| $lines = array(); | ||
| $tempLine = ''; | ||
| $words = explode(' ', $text); | ||
|
|
||
| foreach ($words as $word) { | ||
| if (strlen($tempLine.$word) >= 99) { | ||
| if (strlen($tempLine.$word) === 99) { | ||
| // Adding the extra space will push us to the edge | ||
| // so we are done. | ||
| $lines[] = $tempLine.$word; | ||
| $tempLine = ''; | ||
| } else if (strlen($tempLine.$word) === 100) { | ||
| // We are already at the edge, so we are done. | ||
| $lines[] = $tempLine.$word; | ||
| $tempLine = ''; | ||
| } else { | ||
| $lines[] = rtrim($tempLine); | ||
| $tempLine = $word.' '; | ||
| } | ||
| } else { | ||
| $tempLine .= $word.' '; | ||
| } | ||
| }//end foreach | ||
|
|
||
| if ($tempLine !== '') { | ||
| $lines[] = rtrim($tempLine); | ||
| } | ||
|
|
||
| echo implode(PHP_EOL, $lines).PHP_EOL.PHP_EOL; | ||
|
|
||
| }//end printTextBlock() | ||
|
|
||
|
|
||
| /** | ||
| * Print a code comparison block found in a standard. | ||
| * | ||
| * @param DOMNode $node The DOMNode object for the code comparison block. | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function printCodeComparisonBlock($node) | ||
| { | ||
| $codeBlocks = $node->getElementsByTagName('code'); | ||
| $first = trim($codeBlocks->item(0)->nodeValue); | ||
| $firstTitle = $codeBlocks->item(0)->getAttribute('title'); | ||
|
|
||
| $firstTitleLines = array(); | ||
| $tempTitle = ''; | ||
| $words = explode(' ', $firstTitle); | ||
|
|
||
| foreach ($words as $word) { | ||
| if (strlen($tempTitle.$word) >= 45) { | ||
| if (strlen($tempTitle.$word) === 45) { | ||
| // Adding the extra space will push us to the edge | ||
| // so we are done. | ||
| $firstTitleLines[] = $tempTitle.$word; | ||
| $tempTitle = ''; | ||
| } else if (strlen($tempTitle.$word) === 46) { | ||
| // We are already at the edge, so we are done. | ||
| $firstTitleLines[] = $tempTitle.$word; | ||
| $tempTitle = ''; | ||
| } else { | ||
| $firstTitleLines[] = $tempTitle; | ||
| $tempTitle = $word; | ||
| } | ||
| } else { | ||
| $tempTitle .= $word.' '; | ||
| } | ||
| }//end foreach | ||
|
|
||
| if ($tempTitle !== '') { | ||
| $firstTitleLines[] = $tempTitle; | ||
| } | ||
|
|
||
| $first = str_replace('<em>', '', $first); | ||
| $first = str_replace('</em>', '', $first); | ||
| $firstLines = explode("\n", $first); | ||
|
|
||
| $second = trim($codeBlocks->item(1)->nodeValue); | ||
| $secondTitle = $codeBlocks->item(1)->getAttribute('title'); | ||
|
|
||
| $secondTitleLines = array(); | ||
| $tempTitle = ''; | ||
| $words = explode(' ', $secondTitle); | ||
|
|
||
| foreach ($words as $word) { | ||
| if (strlen($tempTitle.$word) >= 45) { | ||
| if (strlen($tempTitle.$word) === 45) { | ||
| // Adding the extra space will push us to the edge | ||
| // so we are done. | ||
| $secondTitleLines[] = $tempTitle.$word; | ||
| $tempTitle = ''; | ||
| } else if (strlen($tempTitle.$word) === 46) { | ||
| // We are already at the edge, so we are done. | ||
| $secondTitleLines[] = $tempTitle.$word; | ||
| $tempTitle = ''; | ||
| } else { | ||
| $secondTitleLines[] = $tempTitle; | ||
| $tempTitle = $word; | ||
| } | ||
| } else { | ||
| $tempTitle .= $word.' '; | ||
| } | ||
| }//end foreach | ||
|
|
||
| if ($tempTitle !== '') { | ||
| $secondTitleLines[] = $tempTitle; | ||
| } | ||
|
|
||
| $second = str_replace('<em>', '', $second); | ||
| $second = str_replace('</em>', '', $second); | ||
| $secondLines = explode("\n", $second); | ||
|
|
||
| $maxCodeLines = max(count($firstLines), count($secondLines)); | ||
| $maxTitleLines = max(count($firstTitleLines), count($secondTitleLines)); | ||
|
|
||
| echo str_repeat('-', 41); | ||
| echo ' CODE COMPARISON '; | ||
| echo str_repeat('-', 42).PHP_EOL; | ||
|
|
||
| for ($i = 0; $i < $maxTitleLines; $i++) { | ||
| if (isset($firstTitleLines[$i]) === true) { | ||
| $firstLineText = $firstTitleLines[$i]; | ||
| } else { | ||
| $firstLineText = ''; | ||
| } | ||
|
|
||
| if (isset($secondTitleLines[$i]) === true) { | ||
| $secondLineText = $secondTitleLines[$i]; | ||
| } else { | ||
| $secondLineText = ''; | ||
| } | ||
|
|
||
| echo '| '; | ||
| echo $firstLineText.str_repeat(' ', (46 - strlen($firstLineText))); | ||
| echo ' | '; | ||
| echo $secondLineText.str_repeat(' ', (47 - strlen($secondLineText))); | ||
| echo ' |'.PHP_EOL; | ||
| }//end for | ||
|
|
||
| echo str_repeat('-', 100).PHP_EOL; | ||
|
|
||
| for ($i = 0; $i < $maxCodeLines; $i++) { | ||
| if (isset($firstLines[$i]) === true) { | ||
| $firstLineText = $firstLines[$i]; | ||
| } else { | ||
| $firstLineText = ''; | ||
| } | ||
|
|
||
| if (isset($secondLines[$i]) === true) { | ||
| $secondLineText = $secondLines[$i]; | ||
| } else { | ||
| $secondLineText = ''; | ||
| } | ||
|
|
||
| echo '| '; | ||
| echo $firstLineText.str_repeat(' ', (47 - strlen($firstLineText))); | ||
| echo '| '; | ||
| echo $secondLineText.str_repeat(' ', (48 - strlen($secondLineText))); | ||
| echo '|'.PHP_EOL; | ||
| }//end for | ||
|
|
||
| echo str_repeat('-', 100).PHP_EOL.PHP_EOL; | ||
|
|
||
| }//end printCodeComparisonBlock() | ||
|
|
||
|
|
||
| }//end class | ||
|
|
||
| ?> |
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
| /** | ||
| * An exception thrown by PHP_CodeSniffer when it encounters an unrecoverable error. | ||
| * | ||
| * 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 thrown by PHP_CodeSniffer when it encounters an unrecoverable error. | ||
| * | ||
| * @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_Exception extends Exception | ||
| { | ||
|
|
||
| }//end class | ||
|
|
||
| ?> |