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

Breadcrumb

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

function UnusedVariableSniff::isUsedInForLoopCondition

1 call to UnusedVariableSniff::isUsedInForLoopCondition()
UnusedVariableSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Variables/UnusedVariableSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Variables/UnusedVariableSniff.php, line 307

Class

UnusedVariableSniff

Namespace

SlevomatCodingStandard\Sniffs\Variables

Code

private function isUsedInForLoopCondition(File $phpcsFile, int $variablePointer, string $variableName) : bool {
    $tokens = $phpcsFile->getTokens();
    $parenthesisOpenerPointer = $this->findOpenerOfNestedParentheses($phpcsFile, $variablePointer);
    if ($parenthesisOpenerPointer === null) {
        return false;
    }
    $parenthesisOwnerPointer = $this->findOwnerOfNestedParentheses($phpcsFile, $variablePointer);
    if ($parenthesisOwnerPointer === null) {
        return false;
    }
    if ($tokens[$parenthesisOwnerPointer]['code'] !== T_FOR) {
        return false;
    }
    for ($i = $parenthesisOpenerPointer + 1; $i < $tokens[$parenthesisOwnerPointer]['parenthesis_closer']; $i++) {
        if ($i === $variablePointer) {
            continue;
        }
        if ($tokens[$i]['code'] !== T_VARIABLE) {
            continue;
        }
        if ($tokens[$i]['content'] !== $variableName) {
            continue;
        }
        return true;
    }
    return false;
}

API Navigation

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