Commit: 92cd2fd3ec1a2df6310fb6c7775906d815eefd91

Author: Marke Hallowell | Date: 2010-01-31 01:27:36 -0800
Added rule to check doc tags order.
diff --git a/config/phpca_lithium_standard.ini b/config/phpca_lithium_standard.ini index 6e34613..9faeab2 100644 --- a/config/phpca_lithium_standard.ini +++ b/config/phpca_lithium_standard.ini @@ -34,6 +34,7 @@ line_length = 100 [NoWhitespaceWithinCastsRule] [OneSpaceAfterCastsRule] [OperatorsSurroundedBySpacesRule] +[DocTagsOrderRule] ; Documentation ; [ClassesMustHaveDocBlockRule] diff --git a/extensions/phpca/Rule/DocTagsOrderRule.php b/extensions/phpca/Rule/DocTagsOrderRule.php new file mode 100644 index 0000000..8d8e2dc --- /dev/null +++ b/extensions/phpca/Rule/DocTagsOrderRule.php @@ -0,0 +1,53 @@ +<?php + +namespace spriebsch\PHPca\Rule; + +use spriebsch\PHPca\Token; + +/** + * Ensures all constants are uppercase + */ +class DocTagsOrderRule extends Rule { + + protected $tagsOrdered = array ( + "@link", + "@see", + "@params", + "@return" + ); + + /** + * Performs the rule check + * + * @return null + */ + protected function doCheck() { + while ($this->file->seekTokenId(T_DOC_COMMENT)) { + $token = $this->file->current(); + + $docText = $token->getText(); + + $docTags = array(); + + preg_match_all('/@.*?\s/', $docText, $docTags); + + $docIndex = 0; + foreach ($this->tagsOrdered as $tag) { + $tagIndex = array_search($tag . " ", $docTags[0]); + if ($tagIndex !== false) { + if ($tagIndex < $docIndex) { + $this->addViolation("Doc tags not ordered correctly", $token); + //Break so there is only one violation per code block + break; + } + + $docIndex = $tagIndex; + } + + } + $this->file->next(); + } + } +} + +?> \ No newline at end of file