public function CommentEmptyLineSniff::process in Coder 8.3
Same name and namespace in other branches
- 8.2 coder_sniffer/DrupalPractice/Sniffs/Commenting/CommentEmptyLineSniff.php \DrupalPractice\Sniffs\Commenting\CommentEmptyLineSniff::process()
- 8.3.x coder_sniffer/DrupalPractice/Sniffs/Commenting/CommentEmptyLineSniff.php \DrupalPractice\Sniffs\Commenting\CommentEmptyLineSniff::process()
Processes this test, when one of its tokens is encountered.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
int $stackPtr The position of the current token: in the stack passed in $tokens.
Return value
void
File
- coder_sniffer/
DrupalPractice/ Sniffs/ Commenting/ CommentEmptyLineSniff.php, line 48
Class
- CommentEmptyLineSniff
- Throws a warning if there is a blank line after an inline comment.
Namespace
DrupalPractice\Sniffs\CommentingCode
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile
->getTokens();
$comment = rtrim($tokens[$stackPtr]['content']);
// Only want inline comments.
if (substr($comment, 0, 2) !== '//') {
return;
}
// The line below the last comment cannot be empty.
for ($i = $stackPtr + 1; $i < $phpcsFile->numTokens; $i++) {
if ($tokens[$i]['line'] === $tokens[$stackPtr]['line'] + 1) {
if ($tokens[$i]['code'] !== T_WHITESPACE) {
return;
}
}
else {
if ($tokens[$i]['line'] > $tokens[$stackPtr]['line'] + 1) {
break;
}
}
}
$warning = 'There must be no blank line following an inline comment';
$phpcsFile
->addWarning($warning, $stackPtr, 'SpacingAfter');
}