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

Breadcrumb

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

function IndentationHelper::fixIndentation

*

Parameters

list<int> $codePointers:

2 calls to IndentationHelper::fixIndentation()
EarlyExitSniff::processElse in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/EarlyExitSniff.php
EarlyExitSniff::processIf in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/EarlyExitSniff.php

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/IndentationHelper.php, line 53

Class

IndentationHelper
@internal

Namespace

SlevomatCodingStandard\Helpers

Code

public static function fixIndentation(File $phpcsFile, array $codePointers, string $defaultIndentation) : string {
    $tokens = $phpcsFile->getTokens();
    $eolLength = strlen($phpcsFile->eolChar);
    $code = '';
    $inHeredoc = false;
    foreach ($codePointers as $no => $codePointer) {
        $content = $tokens[$codePointer]['content'];
        if (!$inHeredoc && ($no === 0 || substr($tokens[$codePointer - 1]['content'], -$eolLength) === $phpcsFile->eolChar)) {
            if ($content === $phpcsFile->eolChar) {
                // Nothing
            }
            elseif ($content[0] === self::TAB_INDENT) {
                $content = substr($content, 1);
            }
            elseif (substr($content, 0, self::DEFAULT_INDENTATION_WIDTH) === self::SPACES_INDENT) {
                $content = substr($content, self::DEFAULT_INDENTATION_WIDTH);
            }
            else {
                $content = $defaultIndentation . ltrim($content);
            }
        }
        if (in_array($tokens[$codePointer]['code'], [
            T_START_HEREDOC,
            T_START_NOWDOC,
        ], true)) {
            $inHeredoc = true;
        }
        elseif (in_array($tokens[$codePointer]['code'], [
            T_END_HEREDOC,
            T_END_NOWDOC,
        ], true)) {
            $inHeredoc = false;
        }
        $code .= $content;
    }
    return rtrim($code);
}

API Navigation

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