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

Breadcrumb

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

function FunctionCall::getArgument

Returns start and end token for a given argument number.

Parameters

int $number Indicates which argument should be examined, starting with: 1 for the first argument.

Return value

array<string, int>|false

17 calls to FunctionCall::getArgument()
CheckPlainSniff::processFunctionCall in vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CheckPlainSniff.php
Processes this function call.
CurlSslVerifierSniff::processFunctionCall in vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CurlSslVerifierSniff.php
Processes this function call.
DbQuerySniff::processFunctionCall in vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbQuerySniff.php
Processes this function call.
DbSelectBracesSniff::processFunctionCall in vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbSelectBracesSniff.php
Processes this function call.
FormErrorTSniff::processFunctionCall in vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/FormErrorTSniff.php
Processes this function call.

... See full list

File

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php, line 175

Class

FunctionCall
Helper class to sniff for specific function calls.

Namespace

Drupal\Sniffs\Semantics

Code

public function getArgument($number) {
    // Check if we already calculated the tokens for this argument.
    if (isset($this->arguments[$number]) === true) {
        return $this->arguments[$number];
    }
    $tokens = $this->phpcsFile
        ->getTokens();
    // Start token of the first argument.
    $start = $this->phpcsFile
        ->findNext(Tokens::$emptyTokens, $this->openBracket + 1, null, true);
    if ($start === $this->closeBracket) {
        // Function call has no arguments, so return false.
        return false;
    }
    // End token of the last argument.
    $end = $this->phpcsFile
        ->findPrevious(Tokens::$emptyTokens, $this->closeBracket - 1, null, true);
    $lastArgEnd = $end;
    $nextSeparator = $this->openBracket;
    $counter = 1;
    while (($nextSeparator = $this->phpcsFile
        ->findNext(T_COMMA, $nextSeparator + 1, $this->closeBracket)) !== false) {
        // Make sure the comma belongs directly to this function call,
        // and is not inside a nested function call or array.
        $brackets = $tokens[$nextSeparator]['nested_parenthesis'];
        $lastBracket = array_pop($brackets);
        if ($lastBracket !== $this->closeBracket) {
            continue;
        }
        // Update the end token of the current argument.
        $end = $this->phpcsFile
            ->findPrevious(Tokens::$emptyTokens, $nextSeparator - 1, null, true);
        // Save the calculated findings for the current argument.
        $this->arguments[$counter] = [
            'start' => $start,
            'end' => $end,
        ];
        if ($counter === $number) {
            break;
        }
        $counter++;
        $start = $this->phpcsFile
            ->findNext(Tokens::$emptyTokens, $nextSeparator + 1, null, true);
        $end = $lastArgEnd;
    }
    
    //end while
    // If the counter did not reach the passed number something is wrong.
    if ($counter !== $number) {
        return false;
    }
    $this->arguments[$counter] = [
        'start' => $start,
        'end' => $end,
    ];
    return $this->arguments[$counter];
}

API Navigation

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