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

Breadcrumb

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

function YodaHelper::getLeftSideTokens

*

Parameters

array<int, array<string, array<int, int|string>|int|string>> $tokens: * @return array<int, array<string, array<int, int|string>|int|string>>

2 calls to YodaHelper::getLeftSideTokens()
DisallowYodaComparisonSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/DisallowYodaComparisonSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
RequireYodaComparisonSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/RequireYodaComparisonSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/YodaHelper.php, line 93

Class

YodaHelper
@internal

Namespace

SlevomatCodingStandard\Helpers

Code

public static function getLeftSideTokens(array $tokens, int $comparisonTokenPointer) : array {
    $parenthesisDepth = 0;
    $shortArrayDepth = 0;
    $examinedTokenPointer = $comparisonTokenPointer;
    $sideTokens = [];
    $stopTokenCodes = self::getStopTokenCodes();
    while (true) {
        $examinedTokenPointer--;
        $examinedToken = $tokens[$examinedTokenPointer];
        
        /** @var string|int $examinedTokenCode */
        $examinedTokenCode = $examinedToken['code'];
        if ($parenthesisDepth === 0 && $shortArrayDepth === 0 && isset($stopTokenCodes[$examinedTokenCode])) {
            break;
        }
        if ($examinedTokenCode === T_CLOSE_SHORT_ARRAY) {
            $shortArrayDepth++;
        }
        elseif ($examinedTokenCode === T_OPEN_SHORT_ARRAY) {
            if ($shortArrayDepth === 0) {
                break;
            }
            $shortArrayDepth--;
        }
        if ($examinedTokenCode === T_CLOSE_PARENTHESIS) {
            $parenthesisDepth++;
        }
        elseif ($examinedTokenCode === T_OPEN_PARENTHESIS) {
            if ($parenthesisDepth === 0) {
                break;
            }
            $parenthesisDepth--;
        }
        $sideTokens[$examinedTokenPointer] = $examinedToken;
    }
    return self::trimWhitespaceTokens(array_reverse($sideTokens, true));
}

API Navigation

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