cvs: pear /PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Commenting FunctionCommentSniff.php

From: Date: Tue, 02 Jan 2007 03:55:52 +0000
Subject: cvs: pear /PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Commenting FunctionCommentSniff.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-43926@lists.php.net to get a copy of this message
squiz Tue Jan 2 03:55:52 2007 UTC Modified files: /pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Commenting FunctionCommentSniff.php Log: Added a warning if an unknown tag is found; Comment checks for Constructor and Destructor method are now handled differently. http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php?r1=1.3&r2=1.4&diff_format=u Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php diff -u pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php:1.3 pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php:1.4 --- pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php:1.3 Tue Dec 19 04:41:48 2006 +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php Tue Jan 2 03:55:51 2007 @@ -10,7 +10,7 @@ * @author Marc McIntyre <mmcintyre@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version CVS: $Id: FunctionCommentSniff.php,v 1.3 2006/12/19 04:41:48 squiz Exp $ + * @version CVS: $Id: FunctionCommentSniff.php,v 1.4 2007/01/02 03:55:51 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ @@ -62,6 +62,13 @@ private $_functionToken = null; /** + * The position in the stack where the class token was found. + * + * @var int + */ + private $_classToken = null; + + /** * The function comment parser for the current method. * * @var PHP_CodeSniffer_Comment_Parser_FunctionCommentParser @@ -133,6 +140,9 @@ } $this->_functionToken = $stackPtr; + if ($tokens[$phpcsFile->findPrevious(T_CLASS, $stackPtr - 1)]['code'] === T_CLASS) { + $this->_classToken = $phpcsFile->findPrevious(T_CLASS, $stackPtr - 1); + } // Find the first doc comment. $commentStart = $this->_phpcsFile->findPrevious(T_DOC_COMMENT, $commentEnd - 1, null, true) + 1; @@ -184,6 +194,13 @@ $phpcsFile->addError($error, $commentStart + $newlineCount); } + // Check for unknown/deprecated tags. + $unknownTags = $this->_fp->getUnknown(); + foreach ($unknownTags as $errorTag) { + $error = ucfirst($errorTag['tag']).' tag is not allowed in function comment'; + $phpcsFile->addWarning($error, $commentStart + $errorTag['line']); + } + }//end process() @@ -224,7 +241,16 @@ */ private function _processReturn($commentStart, $commentEnd) { - if ($this->_methodName !== '__construct') { + // Skip constructor and destructor. + $className = ''; + if ($this->_classToken !== null) { + $className = $this->_phpcsFile->getDeclarationName($this->_classToken); + $className = strtolower(ltrim($className, '_')); + } + $methodName = strtolower(ltrim($this->_methodName, '_')); + $isSpecialMethod = ($this->_methodName === '__construct' || $this->_methodName === '__destruct'); + + if (!$isSpecialMethod && $methodName !== $className) { // Report missing return tag. if ($this->_fp->getReturn() === null) { $error = 'Missing return tag in function comment'; @@ -282,7 +308,7 @@ // Make sure that there is only one space before the var type. if ($param->getWhitespaceBeforeType() !== ' ') { - $error = 'Expected one space before variable type'; + $error = 'Expected 1 space before variable type'; $this->_phpcsFile->addError($error, $errorPos); }

« previous php.pear.cvs (#43926) next »