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

Breadcrumb

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

function VariableHelper::isUsedInCompactFunction

1 call to VariableHelper::isUsedInCompactFunction()
VariableHelper::isUsedInScopeInternal in vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/VariableHelper.php

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/VariableHelper.php, line 59

Class

VariableHelper
@internal

Namespace

SlevomatCodingStandard\Helpers

Code

public static function isUsedInCompactFunction(File $phpcsFile, int $variablePointer, int $stringPointer) : bool {
    $tokens = $phpcsFile->getTokens();
    $stringContent = $tokens[$stringPointer]['content'];
    if (strtolower($stringContent) !== 'compact') {
        return false;
    }
    $parenthesisOpenerPointer = TokenHelper::findNextEffective($phpcsFile, $stringPointer + 1);
    if ($tokens[$parenthesisOpenerPointer]['code'] !== T_OPEN_PARENTHESIS) {
        return false;
    }
    $variableNameWithoutDollar = substr($tokens[$variablePointer]['content'], 1);
    for ($i = $parenthesisOpenerPointer + 1; $i < $tokens[$parenthesisOpenerPointer]['parenthesis_closer']; $i++) {
        if (preg_match('~^([\'"])' . $variableNameWithoutDollar . '\\1$~', $tokens[$i]['content']) !== 0) {
            return true;
        }
    }
    return false;
}
RSS feed
Powered by Drupal