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

Breadcrumb

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

function Fixer::changeCodeBlockIndent

Adjust the indent of a code block.

Parameters

int $start The position of the token in the token stack: to start adjusting the indent from.

int $end The position of the token in the token stack: to end adjusting the indent.

int $change The number of spaces to adjust the indent by: (positive or negative).

Return value

void

File

vendor/squizlabs/php_codesniffer/src/Fixer.php, line 796

Class

Fixer

Namespace

PHP_CodeSniffer

Code

public function changeCodeBlockIndent($start, $end, $change) {
    $tokens = $this->currentFile
        ->getTokens();
    $baseIndent = '';
    if ($change > 0) {
        $baseIndent = str_repeat(' ', $change);
    }
    $useChangeset = false;
    if ($this->inChangeset === false) {
        $this->beginChangeset();
        $useChangeset = true;
    }
    for ($i = $start; $i <= $end; $i++) {
        if ($tokens[$i]['column'] !== 1 || $tokens[$i + 1]['line'] !== $tokens[$i]['line']) {
            continue;
        }
        $length = 0;
        if ($tokens[$i]['code'] === T_WHITESPACE || $tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE) {
            $length = $tokens[$i]['length'];
            $padding = $length + $change;
            if ($padding > 0) {
                $padding = str_repeat(' ', $padding);
            }
            else {
                $padding = '';
            }
            $newContent = $padding . ltrim($tokens[$i]['content']);
        }
        else {
            $newContent = $baseIndent . $tokens[$i]['content'];
        }
        $this->replaceToken($i, $newContent);
    }
    
    //end for
    if ($useChangeset === true) {
        $this->endChangeset();
    }
}
RSS feed
Powered by Drupal