Commit: 0533f27cf4cb7cdd733a618b20c9d2bed41f7290

Author: David Persson | Date: 2009-12-03 22:58:11 +0100
Adding `FunctionParametersMustBeDocumentedRule`.
diff --git a/config/phpca_lithium_standard.ini b/config/phpca_lithium_standard.ini index bcc8493..84806e0 100644 --- a/config/phpca_lithium_standard.ini +++ b/config/phpca_lithium_standard.ini @@ -33,4 +33,4 @@ line_length = 100 ; Documentation ; [ClassesMustHaveDocBlockRule] ; [FunctionsMustHaveDocBlockRule] - +[FunctionParametersMustBeDocumentedRule] diff --git a/extensions/phpca/Rule/FunctionParametersMustBeDocumentedRule.php b/extensions/phpca/Rule/FunctionParametersMustBeDocumentedRule.php new file mode 100644 index 0000000..53a3bbe --- /dev/null +++ b/extensions/phpca/Rule/FunctionParametersMustBeDocumentedRule.php @@ -0,0 +1,55 @@ +<?php + +namespace spriebsch\PHPca\Rule; + +/** + * Ensure that each parameter of a function/method is documented. + */ +class FunctionParametersMustBeDocumentedRule extends Rule +{ + /** + * Performs the rule check. + * + * @returns null + */ + protected function doCheck() + { + while ($this->file->seekTokenId(T_FUNCTION)) { + $function = $this->file->current(); + $signature = array(); + + while ($this->file->current()->getId() != T_OPEN_CURLY) { + $this->file->next(); + $token = $this->file->current(); + + if ($token->getId() == T_VARIABLE) { + $signature[] = $token; + } + } + + if (!$this->file->seekTokenId(T_DOC_COMMENT, true)) { + $this->file->seekToken($function); + $this->file->next(); + continue; + } + $comment = $this->file->current(); + + if (($comment->getEndLine() + 1) != $function->getLine()) { + $this->file->seekToken($function); + $this->file->next(); + continue; + } + $regex = '/@param\s+(?P<types>[\w\|]*)?\s?(?P<names>\$\w*)?/'; + preg_match_all($regex, $comment->getText(), $matches); + + foreach ($signature as $i => $param) { + if (!isset($matches['names'][$i]) || $param->getText() != $matches['names'][$i]) { + $this->addViolation('Parameter is not documented', $param); + } + } + $this->file->seekToken($function); + $this->file->next(); + } + } +} +?> \ No newline at end of file