protected function Drupal_Sniffs_Commenting_InlineCommentSniff::isInCodeExample in Coder 7.2
Determines if a comment line is part of an
?>
<?php/?><?php
example.
Parameters
PHP_CodeSniffer_File $phpcsFile The file being scanned.:
int $stackPtr The position of the current token: in the stack passed in $tokens.
Return value
boolean Returns true if the comment line is within a @code block, false otherwise.
1 call to Drupal_Sniffs_Commenting_InlineCommentSniff::isInCodeExample()
- Drupal_Sniffs_Commenting_InlineCommentSniff::process in coder_sniffer/
Drupal/ Sniffs/ Commenting/ InlineCommentSniff.php - Processes this test, when one of its tokens is encountered.
File
- coder_sniffer/
Drupal/ Sniffs/ Commenting/ InlineCommentSniff.php, line 227
Class
- Drupal_Sniffs_Commenting_InlineCommentSniff
- PHP_CodeSniffer_Sniffs_Drupal_Commenting_InlineCommentSniff.
Code
protected function isInCodeExample(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile
->getTokens();
$prevComment = $stackPtr;
$lastComment = $stackPtr;
while (($prevComment = $phpcsFile
->findPrevious(array(
T_COMMENT,
), $lastComment - 1, null, false)) !== false) {
if ($tokens[$prevComment]['line'] !== $tokens[$lastComment]['line'] - 1) {
return false;
}
if ($tokens[$prevComment]['content'] === '// @code' . $phpcsFile->eolChar) {
return true;
}
if ($tokens[$prevComment]['content'] === '// @endcode' . $phpcsFile->eolChar) {
return false;
}
$lastComment = $prevComment;
}
return false;
}