class NamedArgumentSpacingSniff
Hierarchy
- class \SlevomatCodingStandard\Sniffs\Functions\NamedArgumentSpacingSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of NamedArgumentSpacingSniff
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Functions/ NamedArgumentSpacingSniff.php, line 13
Namespace
SlevomatCodingStandard\Sniffs\FunctionsView source
class NamedArgumentSpacingSniff implements Sniff {
public const CODE_WHITESPACE_BEFORE_COLON = 'WhitespaceBeforeColon';
public const CODE_NO_WHITESPACE_AFTER_COLON = 'NoWhitespaceAfterColon';
/**
* @return list<string>
*/
public function register() : array {
return [
T_PARAM_NAME,
];
}
/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
* @param int $pointer
*/
public function process(File $phpcsFile, $pointer) : void {
$tokens = $phpcsFile->getTokens();
/** @var int $colonPointer */
$colonPointer = TokenHelper::findNext($phpcsFile, T_COLON, $pointer + 1);
$parameterName = $tokens[$pointer]['content'];
if ($colonPointer !== $pointer + 1) {
$fix = $phpcsFile->addFixableError(sprintf('There must be no whitespace between named argument "%s" and colon.', $parameterName), $colonPointer, self::CODE_WHITESPACE_BEFORE_COLON);
if ($fix) {
$phpcsFile->fixer
->replaceToken($colonPointer - 1, '');
}
}
$whitespacePointer = $colonPointer + 1;
if ($tokens[$whitespacePointer]['code'] === T_WHITESPACE && $tokens[$whitespacePointer]['content'] === ' ') {
return;
}
$fix = $phpcsFile->addFixableError(sprintf('There must be exactly one space after colon in named argument "%s".', $parameterName), $colonPointer, self::CODE_NO_WHITESPACE_AFTER_COLON);
if (!$fix) {
return;
}
if ($tokens[$whitespacePointer]['code'] === T_WHITESPACE) {
$phpcsFile->fixer
->replaceToken($whitespacePointer, ' ');
}
else {
$phpcsFile->fixer
->addContent($colonPointer, ' ');
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
NamedArgumentSpacingSniff::CODE_NO_WHITESPACE_AFTER_COLON | public | constant | ||
NamedArgumentSpacingSniff::CODE_WHITESPACE_BEFORE_COLON | public | constant | ||
NamedArgumentSpacingSniff::process | public | function | * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * |
Overrides Sniff::process |
NamedArgumentSpacingSniff::register | public | function | * | Overrides Sniff::register |