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

Breadcrumb

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

function FunctionCallSignatureSniff::process

Processes this test, when one of its tokens is encountered.

Parameters

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

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

Return value

void

Overrides Sniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php, line 86

Class

FunctionCallSignatureSniff

Namespace

PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions

Code

public function process(File $phpcsFile, $stackPtr) {
    $this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen;
    $this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose;
    $tokens = $phpcsFile->getTokens();
    if ($tokens[$stackPtr]['code'] === T_CLOSE_CURLY_BRACKET && isset($tokens[$stackPtr]['scope_condition']) === true) {
        // Not a function call.
        return;
    }
    // Find the next non-empty token.
    $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true);
    if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
        // Not a function call.
        return;
    }
    if (isset($tokens[$openBracket]['parenthesis_closer']) === false) {
        // Not a function call.
        return;
    }
    // Find the previous non-empty token.
    $search = Tokens::$emptyTokens;
    $search[] = T_BITWISE_AND;
    $previous = $phpcsFile->findPrevious($search, $stackPtr - 1, null, true);
    if ($tokens[$previous]['code'] === T_FUNCTION) {
        // It's a function definition, not a function call.
        return;
    }
    $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
    if ($stackPtr + 1 !== $openBracket) {
        // Checking this: $value = my_function[*](...).
        $error = 'Space before opening parenthesis of function call prohibited';
        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeOpenBracket');
        if ($fix === true) {
            $phpcsFile->fixer
                ->beginChangeset();
            for ($i = $stackPtr + 1; $i < $openBracket; $i++) {
                $phpcsFile->fixer
                    ->replaceToken($i, '');
            }
            // Modify the bracket as well to ensure a conflict if the bracket
            // has been changed in some way by another sniff.
            $phpcsFile->fixer
                ->replaceToken($openBracket, '(');
            $phpcsFile->fixer
                ->endChangeset();
        }
    }
    $next = $phpcsFile->findNext(T_WHITESPACE, $closeBracket + 1, null, true);
    if ($tokens[$next]['code'] === T_SEMICOLON) {
        if (isset(Tokens::$emptyTokens[$tokens[$closeBracket + 1]['code']]) === true) {
            $error = 'Space after closing parenthesis of function call prohibited';
            $fix = $phpcsFile->addFixableError($error, $closeBracket, 'SpaceAfterCloseBracket');
            if ($fix === true) {
                $phpcsFile->fixer
                    ->beginChangeset();
                for ($i = $closeBracket + 1; $i < $next; $i++) {
                    $phpcsFile->fixer
                        ->replaceToken($i, '');
                }
                // Modify the bracket as well to ensure a conflict if the bracket
                // has been changed in some way by another sniff.
                $phpcsFile->fixer
                    ->replaceToken($closeBracket, ')');
                $phpcsFile->fixer
                    ->endChangeset();
            }
        }
    }
    // Check if this is a single line or multi-line function call.
    if ($this->isMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens) === true) {
        $this->processMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
    }
    else {
        $this->processSingleLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
    }
}

API Navigation

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