function NamespaceSpacingSniff::checkLinesAfterNamespace
1 call to NamespaceSpacingSniff::checkLinesAfterNamespace()
- NamespaceSpacingSniff::process in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ NamespaceSpacingSniff.php - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ NamespaceSpacingSniff.php, line 117
Class
Namespace
SlevomatCodingStandard\Sniffs\NamespacesCode
private function checkLinesAfterNamespace(File $phpcsFile, int $namespacePointer) : void {
if (array_key_exists('scope_opener', $phpcsFile->getTokens()[$namespacePointer])) {
return;
}
/** @var int $namespaceSemicolonPointer */
$namespaceSemicolonPointer = TokenHelper::findNextLocal($phpcsFile, T_SEMICOLON, $namespacePointer + 1);
$pointerAfterWhitespaceEnd = TokenHelper::findNextNonWhitespace($phpcsFile, $namespaceSemicolonPointer + 1);
if ($pointerAfterWhitespaceEnd === null) {
return;
}
$whitespaceAfterNamespace = TokenHelper::getContent($phpcsFile, $namespaceSemicolonPointer + 1, $pointerAfterWhitespaceEnd - 1);
$actualLinesCountAfterNamespace = substr_count($whitespaceAfterNamespace, $phpcsFile->eolChar) - 1;
if ($actualLinesCountAfterNamespace === $this->linesCountAfterNamespace) {
return;
}
$fix = $phpcsFile->addFixableError(sprintf('Expected %d line%s after namespace statement, found %d.', $this->linesCountAfterNamespace, $this->linesCountAfterNamespace === 1 ? '' : 's', $actualLinesCountAfterNamespace), $namespacePointer, self::CODE_INCORRECT_LINES_COUNT_AFTER_NAMESPACE);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
FixerHelper::removeBetween($phpcsFile, $namespaceSemicolonPointer, $pointerAfterWhitespaceEnd);
for ($i = 0; $i <= $this->linesCountAfterNamespace; $i++) {
$phpcsFile->fixer
->addNewline($namespaceSemicolonPointer);
}
$phpcsFile->fixer
->endChangeset();
}