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

Breadcrumb

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

function Helpers::getAttachedBlockIndicesForElse

*

Parameters

File $phpcsFile: * @param int $stackPtr * * @return int[]

1 call to Helpers::getAttachedBlockIndicesForElse()
VariableAnalysisSniff::processVaribleInsideElse in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
*

File

vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php, line 1139

Class

Helpers

Namespace

VariableAnalysis\Lib

Code

public static function getAttachedBlockIndicesForElse(File $phpcsFile, $stackPtr) {
    $currentElsePtr = $phpcsFile->findPrevious([
        T_ELSE,
        T_ELSEIF,
    ], $stackPtr - 1);
    if (!is_int($currentElsePtr)) {
        throw new \Exception("Cannot find expected else at {$stackPtr}");
    }
    $ifPtr = $phpcsFile->findPrevious([
        T_IF,
    ], $currentElsePtr - 1);
    if (!is_int($ifPtr)) {
        throw new \Exception("Cannot find if for else at {$stackPtr}");
    }
    $blockIndices = [
        $ifPtr,
    ];
    $previousElseIfPtr = $currentElsePtr;
    do {
        $elseIfPtr = $phpcsFile->findPrevious([
            T_ELSEIF,
        ], $previousElseIfPtr - 1, $ifPtr);
        if (is_int($elseIfPtr)) {
            $blockIndices[] = $elseIfPtr;
            $previousElseIfPtr = $elseIfPtr;
        }
    } while (is_int($elseIfPtr));
    return $blockIndices;
}

API Navigation

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