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

Breadcrumb

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

function DisallowImplicitArrayCreationSniff::hasExplicitCreation

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

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Arrays/DisallowImplicitArrayCreationSniff.php, line 168

Class

DisallowImplicitArrayCreationSniff

Namespace

SlevomatCodingStandard\Sniffs\Arrays

Code

private function hasExplicitCreation(File $phpcsFile, int $scopeOpenerPointer, int $scopeCloserPointer, int $variablePointer) : bool {
    $tokens = $phpcsFile->getTokens();
    $variableName = $tokens[$variablePointer]['content'];
    for ($i = $scopeOpenerPointer + 1; $i < $variablePointer; $i++) {
        if ($tokens[$i]['code'] !== T_VARIABLE) {
            continue;
        }
        if ($tokens[$i]['content'] !== $variableName) {
            continue;
        }
        if (!ScopeHelper::isInSameScope($phpcsFile, $variablePointer, $i)) {
            continue;
        }
        $assignmentPointer = TokenHelper::findNextEffective($phpcsFile, $i + 1);
        if ($tokens[$assignmentPointer]['code'] === T_EQUAL) {
            return true;
        }
        $staticPointer = TokenHelper::findPreviousEffective($phpcsFile, $i - 1);
        if ($tokens[$staticPointer]['code'] === T_STATIC) {
            return true;
        }
        if ($this->isCreatedInForeach($phpcsFile, $i, $scopeCloserPointer)) {
            return true;
        }
        if ($this->isCreatedInList($phpcsFile, $i, $scopeOpenerPointer)) {
            return true;
        }
        if ($this->isCreatedByReferencedParameterInFunctionCall($phpcsFile, $i, $scopeOpenerPointer)) {
            return true;
        }
        if ($this->isImportedUsingGlobalStatement($phpcsFile, $i)) {
            return true;
        }
    }
    return false;
}
RSS feed
Powered by Drupal