/**
* Processes the tokens that this sniff is interested in.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
* @param int $stackPtr The position in the stack where
* the token was found.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
$comment = $token['content'];
$isDoubleSlashComment = substr($comment, 0, 2) === '//';
if ($isDoubleSlashComment) {
$hasLeadingSpace = $tokens[$stackPtr]['content'][2] === ' ';
if ($hasLeadingSpace) {
$hasMoreThanOneLeadingSpace = $tokens[$stackPtr]['content'][3] === ' ';
if ($hasMoreThanOneLeadingSpace) {
$fix = $phpcsFile->addFixableWarning('Double slash comments must start with a single space', $stackPtr, 'SingleLeadingSpaceNeeded');
if ($fix) {
$fixedComment = preg_replace('/[ ]+/', ' ', $comment);
$phpcsFile->fixer->replaceToken($stackPtr, $fixedComment);
}
}
} else {
$fix = $phpcsFile->addFixableWarning('Double slash comments must start with a space', $stackPtr, 'LeadingSpaceNeeded');
if ($fix) {
$fixedComment = substr_replace($comment, '// ', 0, 2);
$phpcsFile->fixer->replaceToken($stackPtr, $fixedComment);
}
}
}
}