class CommentHelper
@internal
Hierarchy
- class \SlevomatCodingStandard\Helpers\CommentHelper
Expanded class hierarchy of CommentHelper
7 files declare their use of CommentHelper
- AbstractControlStructureSpacing.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ ControlStructures/ AbstractControlStructureSpacing.php - AlphabeticallySortedUsesSniff.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ AlphabeticallySortedUsesSniff.php - ClassMemberSpacingSniff.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Classes/ ClassMemberSpacingSniff.php - DisallowCommentAfterCodeSniff.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Commenting/ DisallowCommentAfterCodeSniff.php - EmptyCommentSniff.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Commenting/ EmptyCommentSniff.php
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Helpers/ CommentHelper.php, line 16
Namespace
SlevomatCodingStandard\HelpersView source
class CommentHelper {
public static function isLineComment(File $phpcsFile, int $commentPointer) : bool {
return (bool) preg_match('~^(?://|#)(.*)~', $phpcsFile->getTokens()[$commentPointer]['content']);
}
public static function getCommentEndPointer(File $phpcsFile, int $commentStartPointer) : ?int {
$tokens = $phpcsFile->getTokens();
if (array_key_exists('comment_closer', $tokens[$commentStartPointer])) {
return $tokens[$commentStartPointer]['comment_closer'];
}
if (self::isLineComment($phpcsFile, $commentStartPointer)) {
return $commentStartPointer;
}
if (strpos($tokens[$commentStartPointer]['content'], '/*') !== 0) {
// Part of block comment
return null;
}
$commentEndPointer = $commentStartPointer;
for ($i = $commentStartPointer + 1; $i < $phpcsFile->numTokens; $i++) {
if ($tokens[$i]['code'] === T_COMMENT) {
$commentEndPointer = $i;
continue;
}
if (in_array($tokens[$i]['code'], Tokens::$phpcsCommentTokens, true)) {
$commentEndPointer = $i;
continue;
}
break;
}
return $commentEndPointer;
}
public static function getMultilineCommentStartPointer(File $phpcsFile, int $commentEndPointer) : int {
$tokens = $phpcsFile->getTokens();
$commentStartPointer = $commentEndPointer;
do {
$commentBefore = TokenHelper::findPrevious($phpcsFile, TokenHelper::$inlineCommentTokenCodes, $commentStartPointer - 1);
if ($commentBefore === null) {
break;
}
if ($tokens[$commentBefore]['line'] + 1 !== $tokens[$commentStartPointer]['line']) {
break;
}
/** @var int $commentStartPointer */
$commentStartPointer = $commentBefore;
} while (true);
return $commentStartPointer;
}
public static function getMultilineCommentEndPointer(File $phpcsFile, int $commentStartPointer) : int {
$tokens = $phpcsFile->getTokens();
$commentEndPointer = $commentStartPointer;
do {
$commentAfter = TokenHelper::findNext($phpcsFile, TokenHelper::$inlineCommentTokenCodes, $commentEndPointer + 1);
if ($commentAfter === null) {
break;
}
if ($tokens[$commentAfter]['line'] - 1 !== $tokens[$commentEndPointer]['line']) {
break;
}
/** @var int $commentEndPointer */
$commentEndPointer = $commentAfter;
} while (true);
return $commentEndPointer;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
CommentHelper::getCommentEndPointer | public static | function | |
CommentHelper::getMultilineCommentEndPointer | public static | function | |
CommentHelper::getMultilineCommentStartPointer | public static | function | |
CommentHelper::isLineComment | public static | function |