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

Breadcrumb

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

function VariableAnalysisSniff::processVariableAsFunctionParameter

* Process a parameter definition if it is inside a function definition. * * This does not include variables imported by a "use" statement. * *

Parameters

File $phpcsFile: * @param int $stackPtr * @param string $varName * @param int $outerScope * * @return void

1 call to VariableAnalysisSniff::processVariableAsFunctionParameter()
VariableAnalysisSniff::processVariable in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
* Process a normal variable in the code. * * Most importantly, this function determines if the variable use is a "read" * (using the variable for something) or a "write" (an assignment) or, * sometimes, both at once. * …

File

vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php, line 769

Class

VariableAnalysisSniff

Namespace

VariableAnalysis\Sniffs\CodeAnalysis

Code

protected function processVariableAsFunctionParameter(File $phpcsFile, $stackPtr, $varName, $outerScope) {
    Helpers::debug('processVariableAsFunctionParameter', $stackPtr, $varName);
    $tokens = $phpcsFile->getTokens();
    $functionPtr = Helpers::getFunctionIndexForFunctionParameter($phpcsFile, $stackPtr);
    if (!is_int($functionPtr)) {
        throw new \Exception("Function index not found for function argument index {$stackPtr}");
    }
    Helpers::debug('processVariableAsFunctionParameter found function definition', $tokens[$functionPtr]);
    $this->markVariableDeclaration($varName, ScopeType::PARAM, null, $stackPtr, $functionPtr);
    // Are we pass-by-reference?
    $referencePtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true, null, true);
    if ($referencePtr !== false && $tokens[$referencePtr]['code'] === T_BITWISE_AND) {
        Helpers::debug('processVariableAsFunctionParameter found pass-by-reference to scope', $outerScope);
        $varInfo = $this->getOrCreateVariableInfo($varName, $functionPtr);
        $varInfo->referencedVariableScope = $outerScope;
    }
    //  Are we optional with a default?
    if (Helpers::getNextAssignPointer($phpcsFile, $stackPtr) !== null) {
        Helpers::debug('processVariableAsFunctionParameter optional with default');
        $this->markVariableAssignment($varName, $stackPtr, $functionPtr);
    }
    // Are we using constructor promotion? If so, that counts as both definition and use.
    if (Helpers::isConstructorPromotion($phpcsFile, $stackPtr)) {
        Helpers::debug('processVariableAsFunctionParameter constructor promotion');
        $this->markVariableRead($varName, $stackPtr, $outerScope);
    }
}

API Navigation

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