Source for file ClassCommentSniff.php
Documentation is available at ClassCommentSniff.php
* Parses and verifies the class doc comment.
* <li>A class doc comment exists.</li>
* <li>The comment uses the correct docblock style.</li>
* <li>There are no blank lines after the class comment.</li>
* <li>No tags are used in the docblock.</li>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;
class ClassCommentSniff implements Sniff
* Returns an array of tokens this test wants to listen for.
public function register ()
* Processes this test, when one of its tokens is encountered.
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
public function process (File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens ();
$find = Tokens ::$methodPrefixes;
$commentEnd = $phpcsFile->findPrevious ($find, ($stackPtr - 1 ), null , true );
&& $tokens[$commentEnd]['code'] !== T_COMMENT
$phpcsFile->addError ('Missing class doc comment', $stackPtr, 'Missing');
$phpcsFile->recordMetric ($stackPtr, 'Class has doc comment', 'no');
$phpcsFile->recordMetric ($stackPtr, 'Class has doc comment', 'yes');
if ($tokens[$commentEnd]['code'] === T_COMMENT ) {
$phpcsFile->addError ('You must use "/**" style comments for a class comment', $stackPtr, 'WrongStyle');
if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - 1 )) {
$error = 'There must be no blank lines after the class comment';
$phpcsFile->addError ($error, $commentEnd, 'SpacingAfter');
$commentStart = $tokens[$commentEnd]['comment_opener'];
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
$error = '%s tag is not allowed in class comment';
$data = array ($tokens[$tag]['content']);
$phpcsFile->addWarning ($error, $tag, 'TagNotAllowed', $data);
Documentation generated on Mon, 11 Mar 2019 15:27:16 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|