function ReferenceSpacingSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $referencePointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ PHP/ ReferenceSpacingSniff.php, line 47
Class
Namespace
SlevomatCodingStandard\Sniffs\PHPCode
public function process(File $phpcsFile, $referencePointer) : void {
$this->spacesCountAfterReference = SniffSettingsHelper::normalizeInteger($this->spacesCountAfterReference);
if (!$this->isReference($phpcsFile, $referencePointer)) {
return;
}
$pointerAfterWhitespace = TokenHelper::findNextNonWhitespace($phpcsFile, $referencePointer + 1);
$whitespace = TokenHelper::getContent($phpcsFile, $referencePointer + 1, $pointerAfterWhitespace - 1);
$actualSpacesCount = strlen($whitespace);
if ($this->spacesCountAfterReference === $actualSpacesCount) {
return;
}
$errorMessage = $this->spacesCountAfterReference === 0 ? 'There must be no whitespace after reference.' : sprintf('There must be exactly %d whitespace%s after reference.', $this->spacesCountAfterReference, $this->spacesCountAfterReference !== 1 ? 's' : '');
$fix = $phpcsFile->addFixableError($errorMessage, $referencePointer, self::CODE_INCORRECT_SPACES_AFTER_REFERENCE);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
$phpcsFile->fixer
->addContent($referencePointer, str_repeat(' ', $this->spacesCountAfterReference));
FixerHelper::removeBetween($phpcsFile, $referencePointer, $pointerAfterWhitespace);
$phpcsFile->fixer
->endChangeset();
}