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

Breadcrumb

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

function Helpers::getFunctionIndexForFunctionParameter

* Find the index of the function keyword for a token in a function * definition's parameters. * * Does not work for tokens inside the "use". * * Will also work for the parenthesis that make up the function definition's * parameters list. * * For arguments inside a function call, rather than a definition, use * `getFunctionIndexForFunctionCallArgument`. * *

Parameters

File $phpcsFile: * @param int $stackPtr * * @return ?int

6 calls to Helpers::getFunctionIndexForFunctionParameter()
Helpers::findVariableScopeExceptArrowFunctions in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php
* Return the token index of the scope start for a token * * For a variable within a function body, or a variable within a function * definition argument list, this will return the function keyword's index. * * For a variable within a…
Helpers::isConstructorPromotion in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php
* Return true if the token looks like constructor promotion. * * Call on a parameter variable token only. * *
Helpers::isTokenFunctionParameter in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php
*
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. * *
VariableAnalysisSniff::processVariableAsFunctionParameter in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
* Process a parameter definition if it is inside a function definition. * * This does not include variables imported by a "use" statement. * *

... See full list

File

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

Class

Helpers

Namespace

VariableAnalysis\Lib

Code

public static function getFunctionIndexForFunctionParameter(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $token = $tokens[$stackPtr];
    if ($token['code'] === 'PHPCS_T_OPEN_PARENTHESIS') {
        $startOfArguments = $stackPtr;
    }
    elseif ($token['code'] === 'PHPCS_T_CLOSE_PARENTHESIS') {
        if (empty($token['parenthesis_opener'])) {
            return null;
        }
        $startOfArguments = $token['parenthesis_opener'];
    }
    else {
        if (empty($token['nested_parenthesis'])) {
            return null;
        }
        $startingParenthesis = array_keys($token['nested_parenthesis']);
        $startOfArguments = end($startingParenthesis);
    }
    if (!is_int($startOfArguments)) {
        return null;
    }
    $nonFunctionTokenTypes = Tokens::$emptyTokens;
    $nonFunctionTokenTypes[] = T_STRING;
    $nonFunctionTokenTypes[] = T_BITWISE_AND;
    $functionPtr = self::getIntOrNull($phpcsFile->findPrevious($nonFunctionTokenTypes, $startOfArguments - 1, null, true, null, true));
    if (!is_int($functionPtr)) {
        return null;
    }
    $functionToken = $tokens[$functionPtr];
    $functionTokenTypes = [
        T_FUNCTION,
        T_CLOSURE,
    ];
    if (!in_array($functionToken['code'], $functionTokenTypes, true) && !self::isArrowFunction($phpcsFile, $functionPtr)) {
        return null;
    }
    return $functionPtr;
}

API Navigation

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