public function TodoCommentSniff::process in Coder 8.3
Same name and namespace in other branches
- 8.3.x coder_sniffer/Drupal/Sniffs/Commenting/TodoCommentSniff.php \Drupal\Sniffs\Commenting\TodoCommentSniff::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/
Drupal/ Sniffs/ Commenting/ TodoCommentSniff.php, line 65
Class
- TodoCommentSniff
- Parses and verifies that comments use the correct @todo format.
Namespace
Drupal\Sniffs\CommentingCode
public function process(File $phpcsFile, $stackPtr) {
$debug = Config::getConfigData('todo_debug');
if ($debug !== null) {
$this->debug = (bool) $debug;
}
$tokens = $phpcsFile
->getTokens();
if ($this->debug === true) {
echo "\n------\n\$tokens[{$stackPtr}] = " . print_r($tokens[$stackPtr], true) . PHP_EOL;
echo 'code = ' . $tokens[$stackPtr]['code'] . ', type = ' . $tokens[$stackPtr]['type'] . "\n";
}
// Standard comments and multi-line comments where the "@" is missing so
// it does not register as a T_DOC_COMMENT_TAG.
if ($tokens[$stackPtr]['code'] === T_COMMENT || $tokens[$stackPtr]['code'] === T_DOC_COMMENT_STRING) {
$comment = $tokens[$stackPtr]['content'];
if ($this->debug === true) {
echo "Getting \$comment from \$tokens[{$stackPtr}]['content']\n";
}
$this
->checkTodoFormat($phpcsFile, $stackPtr, $comment, $tokens);
}
else {
if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_TAG) {
// Document comment tag (i.e. comments that begin with "@").
// Determine if this is related at all and build the full comment line
// from the various segments that the line is parsed into.
$expression = '/^@to/i';
$comment = $tokens[$stackPtr]['content'];
if ((bool) preg_match($expression, $comment) === true) {
if ($this->debug === true) {
echo "Attempting to build comment\n";
}
$index = $stackPtr + 1;
while ($tokens[$index]['line'] === $tokens[$stackPtr]['line']) {
$comment .= $tokens[$index]['content'];
$index++;
}
if ($this->debug === true) {
echo "Result comment = {$comment}\n";
}
$this
->checkTodoFormat($phpcsFile, $stackPtr, $comment, $tokens);
}
//end if
}
}
//end if
}