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

Breadcrumb

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

function SingleLineArrayWhitespaceSniff::checkWhitespaceAfterOpeningBracket

1 call to SingleLineArrayWhitespaceSniff::checkWhitespaceAfterOpeningBracket()
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 119

Class

SingleLineArrayWhitespaceSniff

Namespace

SlevomatCodingStandard\Sniffs\Arrays

Code

private function checkWhitespaceAfterOpeningBracket(File $phpcsFile, int $arrayStart) : void {
    $tokens = $phpcsFile->getTokens();
    $whitespacePointer = $arrayStart + 1;
    $spaceLength = 0;
    if ($tokens[$whitespacePointer]['code'] === T_WHITESPACE) {
        $spaceLength = $tokens[$whitespacePointer]['length'];
    }
    if ($spaceLength === $this->spacesAroundBrackets) {
        return;
    }
    $error = sprintf('Expected %d spaces after array opening bracket, %d found.', $this->spacesAroundBrackets, $spaceLength);
    $fix = $phpcsFile->addFixableError($error, $arrayStart, self::CODE_SPACE_AFTER_ARRAY_OPEN);
    if (!$fix) {
        return;
    }
    if ($spaceLength === 0) {
        $phpcsFile->fixer
            ->addContent($arrayStart, str_repeat(' ', $this->spacesAroundBrackets));
    }
    else {
        $phpcsFile->fixer
            ->replaceToken($whitespacePointer, str_repeat(' ', $this->spacesAroundBrackets));
    }
}

API Navigation

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