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

Breadcrumb

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

function Helpers::getVariablesDefinedByArrowFunction

*

Parameters

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

1 call to Helpers::getVariablesDefinedByArrowFunction()
Helpers::findVariableScope in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php
*

File

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

Class

Helpers

Namespace

VariableAnalysis\Lib

Code

public static function getVariablesDefinedByArrowFunction(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $arrowFunctionToken = $tokens[$stackPtr];
    $variableNames = [];
    self::debug('looking for variables in arrow function token', $arrowFunctionToken);
    for ($index = $arrowFunctionToken['parenthesis_opener']; $index < $arrowFunctionToken['parenthesis_closer']; $index++) {
        $token = $tokens[$index];
        if ($token['code'] === T_VARIABLE) {
            $variableNames[] = self::normalizeVarName($token['content']);
        }
    }
    self::debug('found these variables in arrow function token', $variableNames);
    return $variableNames;
}
RSS feed
Powered by Drupal