Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NamedArgumentSpacingSniff.php

function NamedArgumentSpacingSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $pointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Functions/NamedArgumentSpacingSniff.php, line 33

Class

NamedArgumentSpacingSniff

Namespace

SlevomatCodingStandard\Sniffs\Functions

Code

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, ' ');
    }
}
RSS feed
Powered by Drupal