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

Breadcrumb

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

function Helpers::getClosestConditionPositionIfBeforeOtherConditions

* Return true if the token conditions are within an IF/ELSE/ELSEIF block * before they are within a class or function. * *

Parameters

(int|string)[] $conditions: * * @return int|string|null

1 call to Helpers::getClosestConditionPositionIfBeforeOtherConditions()
VariableAnalysisSniff::processVariableAsAssignment in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
* Process a variable that is being assigned. * * This will record that the variable has been defined within a scope so that * later we can determine if it it unused and we can guarantee that any * future uses of the variable are not using an…

File

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

Class

Helpers

Namespace

VariableAnalysis\Lib

Code

public static function getClosestConditionPositionIfBeforeOtherConditions(array $conditions) {
    $conditionsInsideOut = array_reverse($conditions, true);
    if (empty($conditions)) {
        return null;
    }
    $scopeCode = reset($conditionsInsideOut);
    $conditionalCodes = [
        T_IF,
        T_ELSE,
        T_ELSEIF,
    ];
    if (in_array($scopeCode, $conditionalCodes, true)) {
        return key($conditionsInsideOut);
    }
    return null;
}

API Navigation

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