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

Breadcrumb

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

function Helpers::isRequireInScopeAfter

*

Parameters

File $phpcsFile: * @param VariableInfo $varInfo * @param ScopeInfo $scopeInfo * * @return bool

1 call to Helpers::isRequireInScopeAfter()
VariableAnalysisSniff::processScopeCloseForVariable in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
* Warn about an unused variable if it has not been used within a scope. * *

File

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

Class

Helpers

Namespace

VariableAnalysis\Lib

Code

public static function isRequireInScopeAfter(File $phpcsFile, VariableInfo $varInfo, ScopeInfo $scopeInfo) {
    $requireTokens = [
        T_REQUIRE,
        T_REQUIRE_ONCE,
        T_INCLUDE,
        T_INCLUDE_ONCE,
    ];
    $indexToStartSearch = $varInfo->firstDeclared;
    if (!empty($varInfo->firstInitialized)) {
        $indexToStartSearch = $varInfo->firstInitialized;
    }
    $tokens = $phpcsFile->getTokens();
    $indexToStopSearch = isset($tokens[$scopeInfo->scopeStartIndex]['scope_closer']) ? $tokens[$scopeInfo->scopeStartIndex]['scope_closer'] : null;
    if (!is_int($indexToStartSearch) || !is_int($indexToStopSearch)) {
        return false;
    }
    $requireTokenIndex = $phpcsFile->findNext($requireTokens, $indexToStartSearch + 1, $indexToStopSearch);
    if (is_int($requireTokenIndex)) {
        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