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

Breadcrumb

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

function PropertyLabelSpacingSniff::process

Processes this test, when one of its tokens is encountered.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token: in the stack passed in $tokens.

Return value

void

Overrides Sniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/PropertyLabelSpacingSniff.php, line 52

Class

PropertyLabelSpacingSniff

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $colon = $phpcsFile->findNext(T_COLON, $stackPtr + 1);
    if ($colon !== $stackPtr + 1) {
        $error = 'There must be no space before the colon in a property/label declaration';
        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before');
        if ($fix === true) {
            $phpcsFile->fixer
                ->replaceToken($stackPtr + 1, '');
        }
    }
    if ($tokens[$colon + 1]['code'] !== T_WHITESPACE || $tokens[$colon + 1]['content'] !== ' ') {
        $error = 'There must be a single space after the colon in a property/label declaration';
        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'After');
        if ($fix === true) {
            if ($tokens[$colon + 1]['code'] === T_WHITESPACE) {
                $phpcsFile->fixer
                    ->replaceToken($colon + 1, ' ');
            }
            else {
                $phpcsFile->fixer
                    ->addContent($colon, ' ');
            }
        }
    }
}
RSS feed
Powered by Drupal