function DisallowMultipleAttributesPerLineSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $attributeOpenerPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Attributes/ DisallowMultipleAttributesPerLineSniff.php, line 30
Class
Namespace
SlevomatCodingStandard\Sniffs\AttributesCode
public function process(File $phpcsFile, $attributeOpenerPointer) : void {
if (!AttributeHelper::isValidAttribute($phpcsFile, $attributeOpenerPointer)) {
return;
}
$tokens = $phpcsFile->getTokens();
$attributeCloserPointer = $tokens[$attributeOpenerPointer]['attribute_closer'];
$nextAttributeOpenerPointer = TokenHelper::findNext($phpcsFile, T_ATTRIBUTE, $attributeCloserPointer + 1);
if ($nextAttributeOpenerPointer === null) {
return;
}
if ($tokens[$attributeCloserPointer]['line'] !== $tokens[$nextAttributeOpenerPointer]['line']) {
return;
}
$attributeTargetPointer = AttributeHelper::getAttributeTarget($phpcsFile, $attributeOpenerPointer);
$nextAttributeTargetPointer = AttributeHelper::getAttributeTarget($phpcsFile, $nextAttributeOpenerPointer);
if ($attributeTargetPointer !== $nextAttributeTargetPointer) {
return;
}
$fix = $phpcsFile->addFixableError('Multiple attributes per line are disallowed.', $nextAttributeOpenerPointer, self::CODE_DISALLOWED_MULTIPLE_ATTRIBUTES_PER_LINE);
if (!$fix) {
return;
}
$nonWhitespacePointerBefore = TokenHelper::findPreviousNonWhitespace($phpcsFile, $nextAttributeOpenerPointer - 1);
$indentation = IndentationHelper::getIndentation($phpcsFile, TokenHelper::findFirstNonWhitespaceOnLine($phpcsFile, $attributeOpenerPointer));
$phpcsFile->fixer
->beginChangeset();
FixerHelper::removeBetween($phpcsFile, $nonWhitespacePointerBefore, $nextAttributeOpenerPointer);
$phpcsFile->fixer
->addContentBefore($nextAttributeOpenerPointer, $phpcsFile->eolChar . $indentation);
$phpcsFile->fixer
->endChangeset();
}