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

Breadcrumb

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

function Helpers::areConditionsWithinFunctionBeforeClass

* Return true if the token conditions are within a function before they are * within a class. * *

Parameters

array{conditions: (int|string)[], content: string} $token: * * @return bool

1 call to Helpers::areConditionsWithinFunctionBeforeClass()
VariableAnalysisSniff::processVariableAsClassProperty in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
* Process a class property that is being defined. * * Property definitions are ignored currently because all property access is * legal, even to undefined properties. * * Can be called for any token and will return false if the variable is…

File

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

Class

Helpers

Namespace

VariableAnalysis\Lib

Code

public static function areConditionsWithinFunctionBeforeClass(array $token) {
    $conditions = $token['conditions'];
    $classlikeCodes = [
        T_CLASS,
        T_ANON_CLASS,
        T_TRAIT,
    ];
    if (defined('T_ENUM')) {
        $classlikeCodes[] = T_ENUM;
    }
    $classlikeCodes[] = 'PHPCS_T_ENUM';
    foreach (array_reverse($conditions, true) as $scopeCode) {
        if (in_array($scopeCode, $classlikeCodes)) {
            return false;
        }
        if ($scopeCode === T_FUNCTION) {
            return true;
        }
    }
    return false;
}

API Navigation

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