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

Breadcrumb

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

function DisallowImplicitArrayCreationSniff::isCreatedInList

1 call to DisallowImplicitArrayCreationSniff::isCreatedInList()
DisallowImplicitArrayCreationSniff::hasExplicitCreation in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Arrays/DisallowImplicitArrayCreationSniff.php

File

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

Class

DisallowImplicitArrayCreationSniff

Namespace

SlevomatCodingStandard\Sniffs\Arrays

Code

private function isCreatedInList(File $phpcsFile, int $variablePointer, int $scopeOpenerPointer) : bool {
    $tokens = $phpcsFile->getTokens();
    $parenthesisOpenerPointer = TokenHelper::findPrevious($phpcsFile, [
        T_OPEN_PARENTHESIS,
        T_OPEN_SHORT_ARRAY,
        T_OPEN_SQUARE_BRACKET,
    ], $variablePointer - 1, $scopeOpenerPointer);
    if ($parenthesisOpenerPointer === null) {
        return false;
    }
    if ($tokens[$parenthesisOpenerPointer]['code'] === T_OPEN_PARENTHESIS) {
        if ($tokens[$parenthesisOpenerPointer]['parenthesis_closer'] < $variablePointer) {
            return false;
        }
        $pointerBeforeParenthesisOpener = TokenHelper::findPreviousEffective($phpcsFile, $parenthesisOpenerPointer - 1);
        return $tokens[$pointerBeforeParenthesisOpener]['code'] === T_LIST;
    }
    return $tokens[$parenthesisOpenerPointer]['bracket_closer'] > $variablePointer;
}
RSS feed
Powered by Drupal