function NamespaceDeclarationSniff::checkWhitespaceAfterNamespace
1 call to NamespaceDeclarationSniff::checkWhitespaceAfterNamespace()
- NamespaceDeclarationSniff::process in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ NamespaceDeclarationSniff.php - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ NamespaceDeclarationSniff.php, line 52
Class
Namespace
SlevomatCodingStandard\Sniffs\NamespacesCode
private function checkWhitespaceAfterNamespace(File $phpcsFile, int $namespacePointer) : void {
$tokens = $phpcsFile->getTokens();
$whitespacePointer = $namespacePointer + 1;
if ($tokens[$whitespacePointer]['code'] !== T_WHITESPACE) {
$phpcsFile->addError('Expected one space after namespace statement.', $namespacePointer, self::CODE_INVALID_WHITESPACE_AFTER_NAMESPACE);
return;
}
if ($tokens[$whitespacePointer]['content'] === ' ') {
return;
}
$errorMessage = $tokens[$whitespacePointer]['content'][0] === "\t" ? 'Expected one space after namespace statement, found tab.' : sprintf('Expected one space after namespace statement, found %d.', strlen($tokens[$whitespacePointer]['content']));
$fix = $phpcsFile->addFixableError($errorMessage, $namespacePointer, self::CODE_INVALID_WHITESPACE_AFTER_NAMESPACE);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
$phpcsFile->fixer
->replaceToken($whitespacePointer, ' ');
$phpcsFile->fixer
->endChangeset();
}