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

Breadcrumb

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

function VariableAnalysisSniff::markVariableAssignmentWithoutInitialization

* Record that a variable has been assigned a value. * * Does not record that a variable has been defined, which is the usual state * of affairs. For that, use `markVariableAssignment()`. * * This is useful for assignments to references. * *

Parameters

string $varName: * @param int $stackPtr * @param int $currScope * * @return void

2 calls to VariableAnalysisSniff::markVariableAssignmentWithoutInitialization()
VariableAnalysisSniff::markVariableAssignment in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
* Record that a variable has been defined and assigned a value. * * If a variable has been defined within a scope, it will not be marked as * undefined when that variable is later used. If it is not used, it will be * marked as unused when…
VariableAnalysisSniff::processVariableAsAssignment in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
* Process a variable that is being assigned. * * This will record that the variable has been defined within a scope so that * later we can determine if it it unused and we can guarantee that any * future uses of the variable are not using an…

File

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

Class

VariableAnalysisSniff

Namespace

VariableAnalysis\Sniffs\CodeAnalysis

Code

protected function markVariableAssignmentWithoutInitialization($varName, $stackPtr, $currScope) {
    $varInfo = $this->getOrCreateVariableInfo($varName, $currScope);
    // Is the variable referencing another variable? If so, mark that variable used also.
    if ($varInfo->referencedVariableScope !== null && $varInfo->referencedVariableScope !== $currScope) {
        Helpers::debug('markVariableAssignmentWithoutInitialization: considering marking referenced variable assigned', $varName);
        // Don't do this if the referenced variable does not exist; eg: if it's going to be bound at runtime like in array_walk
        if ($this->getVariableInfo($varInfo->name, $varInfo->referencedVariableScope)) {
            Helpers::debug('markVariableAssignmentWithoutInitialization: marking referenced variable as assigned also', $varName);
            $this->markVariableAssignment($varInfo->name, $stackPtr, $varInfo->referencedVariableScope);
        }
        else {
            Helpers::debug('markVariableAssignmentWithoutInitialization: not marking referenced variable assigned', $varName);
        }
    }
    else {
        Helpers::debug('markVariableAssignmentWithoutInitialization: not considering referenced variable', $varName);
    }
    if (empty($varInfo->scopeType)) {
        $varInfo->scopeType = ScopeType::LOCAL;
    }
    $varInfo->allAssignments[] = $stackPtr;
}

API Navigation

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