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

Breadcrumb

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

function FunctionCallSignatureSniff::isMultiLineCall

Same name in this branch
  1. 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php \PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions\FunctionCallSignatureSniff::isMultiLineCall()

Processes single-line calls.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token: in the stack passed in $tokens.

int $openBracket The position of the opening bracket: in the stack passed in $tokens.

array $tokens The stack of tokens that make up: the file.

Return value

bool

Overrides FunctionCallSignatureSniff::isMultiLineCall

File

vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Methods/FunctionCallSignatureSniff.php, line 40

Class

FunctionCallSignatureSniff

Namespace

PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods

Code

public function isMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens) {
    // If the first argument is on a new line, this is a multi-line
    // function call, even if there is only one argument.
    $next = $phpcsFile->findNext(Tokens::$emptyTokens, $openBracket + 1, null, true);
    if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
        return true;
    }
    $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
    $end = $phpcsFile->findEndOfStatement($openBracket + 1, [
        T_COLON,
    ]);
    while ($tokens[$end]['code'] === T_COMMA) {
        // If the next bit of code is not on the same line, this is a
        // multi-line function call.
        $next = $phpcsFile->findNext(Tokens::$emptyTokens, $end + 1, $closeBracket, true);
        if ($next === false) {
            return false;
        }
        if ($tokens[$next]['line'] !== $tokens[$end]['line']) {
            return true;
        }
        $end = $phpcsFile->findEndOfStatement($next, [
            T_COLON,
        ]);
    }
    // We've reached the last argument, so see if the next content
    // (should be the close bracket) is also on the same line.
    $next = $phpcsFile->findNext(Tokens::$emptyTokens, $end + 1, $closeBracket, true);
    if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) {
        return true;
    }
    return false;
}
RSS feed
Powered by Drupal