function ClassDeclarationSniff::processClose
Same name in this branch
- 11.1.x vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php \Drupal\Sniffs\Classes\ClassDeclarationSniff::processClose()
- 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/ClassDeclarationSniff.php \PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\ClassDeclarationSniff::processClose()
Processes the closing section of a class declaration.
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
2 calls to ClassDeclarationSniff::processClose()
- AnonClassDeclarationSniff::process in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ PSR12/ Sniffs/ Classes/ AnonClassDeclarationSniff.php - Processes this test, when one of its tokens is encountered.
- ClassDeclarationSniff::process in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ PSR2/ Sniffs/ Classes/ ClassDeclarationSniff.php - Processes this test, when one of its tokens is encountered.
2 methods override ClassDeclarationSniff::processClose()
- ClassDeclarationSniff::processClose in vendor/
drupal/ coder/ coder_sniffer/ Drupal/ Sniffs/ Classes/ ClassDeclarationSniff.php - Processes the closing section of a class declaration.
- ClassDeclarationSniff::processClose in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Classes/ ClassDeclarationSniff.php - Processes the closing section of a class declaration.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ PSR2/ Sniffs/ Classes/ ClassDeclarationSniff.php, line 493
Class
Namespace
PHP_CodeSniffer\Standards\PSR2\Sniffs\ClassesCode
public function processClose(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
// Check that the closing brace comes right after the code body.
$closeBrace = $tokens[$stackPtr]['scope_closer'];
$prevContent = $phpcsFile->findPrevious(T_WHITESPACE, $closeBrace - 1, null, true);
if ($prevContent !== $tokens[$stackPtr]['scope_opener'] && $tokens[$prevContent]['line'] !== $tokens[$closeBrace]['line'] - 1) {
$error = 'The closing brace for the %s must go on the next line after the body';
$data = [
$tokens[$stackPtr]['content'],
];
$fix = $phpcsFile->addFixableError($error, $closeBrace, 'CloseBraceAfterBody', $data);
if ($fix === true) {
$phpcsFile->fixer
->beginChangeset();
for ($i = $prevContent + 1; $tokens[$i]['line'] !== $tokens[$closeBrace]['line']; $i++) {
$phpcsFile->fixer
->replaceToken($i, '');
}
if (strpos($tokens[$prevContent]['content'], $phpcsFile->eolChar) === false) {
$phpcsFile->fixer
->addNewline($prevContent);
}
$phpcsFile->fixer
->endChangeset();
}
}
//end if
if ($tokens[$stackPtr]['code'] !== T_ANON_CLASS) {
// Check the closing brace is on it's own line, but allow
// for comments like "//end class".
$ignoreTokens = Tokens::$phpcsCommentTokens;
$ignoreTokens[] = T_WHITESPACE;
$ignoreTokens[] = T_COMMENT;
$ignoreTokens[] = T_SEMICOLON;
$nextContent = $phpcsFile->findNext($ignoreTokens, $closeBrace + 1, null, true);
if ($tokens[$nextContent]['line'] === $tokens[$closeBrace]['line']) {
$type = strtolower($tokens[$stackPtr]['content']);
$error = 'Closing %s brace must be on a line by itself';
$data = [
$type,
];
$phpcsFile->addError($error, $closeBrace, 'CloseBraceSameLine', $data);
}
}
}