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

Breadcrumb

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

function Helpers::isArrowFunction

*

Parameters

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

7 calls to Helpers::isArrowFunction()
Helpers::getFunctionIndexForFunctionCallArgument in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php
* Find the index of the function keyword for a token in a function call's arguments * * For the variable `$foo` in the expression `doSomething($foo)`, this will * return the index of the `doSomething` token. * *
Helpers::getFunctionIndexForFunctionParameter in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php
* 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 …
Helpers::getPreviousArrowFunctionIndex in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php
* Move back from the stackPtr to the start of the enclosing scope until we * find a 'fn' token that starts an arrow function, returning the index of * that token. Returns null if there are no arrow functions before stackPtr. * * Note…
Helpers::getScopeCloseForScopeOpen in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php
*
Helpers::getStartOfTokenScope in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php
* Return the token index of the scope start for a variable token * * This will only work for a variable within a function's body. Otherwise, * see `findVariableScope`, which is more complex. * * Note that if used on a variable in an…

... See full list

File

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

Class

Helpers

Namespace

VariableAnalysis\Lib

Code

public static function isArrowFunction(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    if (defined('T_FN') && $tokens[$stackPtr]['code'] === T_FN) {
        return true;
    }
    if ($tokens[$stackPtr]['content'] !== 'fn') {
        return false;
    }
    // Make sure next non-space token is an open parenthesis
    $openParenIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true);
    if (!is_int($openParenIndex) || $tokens[$openParenIndex]['code'] !== T_OPEN_PARENTHESIS) {
        return false;
    }
    // Find the associated close parenthesis
    $closeParenIndex = $tokens[$openParenIndex]['parenthesis_closer'];
    // Make sure the next token is a fat arrow
    $fatArrowIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $closeParenIndex + 1, null, true);
    if (!is_int($fatArrowIndex)) {
        return false;
    }
    if ($tokens[$fatArrowIndex]['code'] !== T_DOUBLE_ARROW && $tokens[$fatArrowIndex]['type'] !== 'T_FN_ARROW') {
        return false;
    }
    return true;
}
RSS feed
Powered by Drupal