function InlineCommentSniff::process
Same name in this branch
- 11.1.x vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php \Drupal\Sniffs\Commenting\InlineCommentSniff::process()
- 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php \PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\InlineCommentSniff::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
Overrides Sniff::process
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ PEAR/ Sniffs/ Commenting/ InlineCommentSniff.php, line 40
Class
Namespace
PHP_CodeSniffer\Standards\PEAR\Sniffs\CommentingCode
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr]['content'][0] === '#') {
$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '# ...');
$error = 'Perl-style comments are not allowed. Use "// Comment."';
$error .= ' or "/* comment */" instead.';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle');
if ($fix === true) {
$newComment = ltrim($tokens[$stackPtr]['content'], '# ');
$newComment = '// ' . $newComment;
$phpcsFile->fixer
->replaceToken($stackPtr, $newComment);
}
}
else {
if ($tokens[$stackPtr]['content'][0] === '/' && $tokens[$stackPtr]['content'][1] === '/') {
$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '// ...');
}
else {
if ($tokens[$stackPtr]['content'][0] === '/' && $tokens[$stackPtr]['content'][1] === '*') {
$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '/* ... */');
}
}
}
}