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

Breadcrumb

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

function SingleLineArrayWhitespaceSniff::checkWhitespaceAfterComma

1 call to SingleLineArrayWhitespaceSniff::checkWhitespaceAfterComma()
SingleLineArrayWhitespaceSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Arrays/SingleLineArrayWhitespaceSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Arrays/SingleLineArrayWhitespaceSniff.php, line 200

Class

SingleLineArrayWhitespaceSniff

Namespace

SlevomatCodingStandard\Sniffs\Arrays

Code

private function checkWhitespaceAfterComma(File $phpcsFile, int $comma) : void {
    $tokens = $phpcsFile->getTokens();
    if ($tokens[$comma + 1]['code'] !== T_WHITESPACE) {
        $error = sprintf('Expected 1 space between comma and "%s", 0 found.', $tokens[$comma + 1]['content']);
        $fix = $phpcsFile->addFixableError($error, $comma, self::CODE_SPACE_AFTER_COMMA);
        if ($fix) {
            $phpcsFile->fixer
                ->addContent($comma, ' ');
        }
        return;
    }
    $spaceLength = $tokens[$comma + 1]['length'];
    if ($spaceLength === 1) {
        return;
    }
    $error = sprintf('Expected 1 space between comma and "%s", %d found.', $tokens[$comma + 2]['content'], $spaceLength);
    $fix = $phpcsFile->addFixableError($error, $comma, self::CODE_SPACE_AFTER_COMMA);
    if (!$fix) {
        return;
    }
    $phpcsFile->fixer
        ->replaceToken($comma + 1, ' ');
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal