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

Breadcrumb

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

function SingleLineArrayWhitespaceSniff::checkWhitespaceBeforeClosingBracket

1 call to SingleLineArrayWhitespaceSniff::checkWhitespaceBeforeClosingBracket()
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 147

Class

SingleLineArrayWhitespaceSniff

Namespace

SlevomatCodingStandard\Sniffs\Arrays

Code

private function checkWhitespaceBeforeClosingBracket(File $phpcsFile, int $arrayEnd) : void {
    $tokens = $phpcsFile->getTokens();
    $whitespacePointer = $arrayEnd - 1;
    $spaceLength = 0;
    if ($tokens[$whitespacePointer]['code'] === T_WHITESPACE) {
        $spaceLength = $tokens[$whitespacePointer]['length'];
    }
    if ($spaceLength === $this->spacesAroundBrackets) {
        return;
    }
    $error = sprintf('Expected %d spaces before array closing bracket, %d found.', $this->spacesAroundBrackets, $spaceLength);
    $fix = $phpcsFile->addFixableError($error, $arrayEnd, self::CODE_SPACE_BEFORE_ARRAY_CLOSE);
    if (!$fix) {
        return;
    }
    if ($spaceLength === 0) {
        $phpcsFile->fixer
            ->addContentBefore($arrayEnd, 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