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

Breadcrumb

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

function TernaryOperatorHelper::getEndPointer

5 calls to TernaryOperatorHelper::getEndPointer()
RequireMultiLineTernaryOperatorSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/RequireMultiLineTernaryOperatorSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
RequireNullCoalesceOperatorSniff::checkIdenticalOperator in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/RequireNullCoalesceOperatorSniff.php
RequireNullSafeObjectOperatorSniff::checkTernaryOperator in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/RequireNullSafeObjectOperatorSniff.php
RequireShortTernaryOperatorSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/RequireShortTernaryOperatorSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
UselessTernaryOperatorSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/UselessTernaryOperatorSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/TernaryOperatorHelper.php, line 110

Class

TernaryOperatorHelper
@internal

Namespace

SlevomatCodingStandard\Helpers

Code

public static function getEndPointer(File $phpcsFile, int $inlineThenPointer, int $inlineElsePointer) : int {
    $tokens = $phpcsFile->getTokens();
    $pointerAfterInlineElseEnd = $inlineElsePointer;
    do {
        $pointerAfterInlineElseEnd = TokenHelper::findNext($phpcsFile, [
            T_SEMICOLON,
            T_COLON,
            T_COMMA,
            T_DOUBLE_ARROW,
            T_CLOSE_PARENTHESIS,
            T_CLOSE_SHORT_ARRAY,
            T_CLOSE_SQUARE_BRACKET,
            T_COALESCE,
        ], $pointerAfterInlineElseEnd + 1);
        if ($pointerAfterInlineElseEnd === null) {
            continue;
        }
        if ($tokens[$pointerAfterInlineElseEnd]['code'] === T_CLOSE_PARENTHESIS) {
            if ($tokens[$pointerAfterInlineElseEnd]['parenthesis_opener'] < $inlineThenPointer) {
                break;
            }
        }
        elseif (in_array($tokens[$pointerAfterInlineElseEnd]['code'], [
            T_CLOSE_SHORT_ARRAY,
            T_CLOSE_SQUARE_BRACKET,
        ], true)) {
            if ($tokens[$pointerAfterInlineElseEnd]['bracket_opener'] < $inlineThenPointer) {
                break;
            }
        }
        elseif ($tokens[$pointerAfterInlineElseEnd]['code'] === T_COMMA) {
            $previousPointer = TokenHelper::findPrevious($phpcsFile, [
                T_OPEN_PARENTHESIS,
                T_OPEN_SHORT_ARRAY,
            ], $pointerAfterInlineElseEnd - 1, $inlineThenPointer);
            if ($previousPointer === null) {
                break;
            }
            if ($tokens[$previousPointer]['code'] === T_OPEN_PARENTHESIS && $tokens[$previousPointer]['parenthesis_closer'] < $pointerAfterInlineElseEnd) {
                break;
            }
            if ($tokens[$previousPointer]['code'] === T_OPEN_SHORT_ARRAY && $tokens[$previousPointer]['bracket_closer'] < $pointerAfterInlineElseEnd) {
                break;
            }
        }
        elseif ($tokens[$pointerAfterInlineElseEnd]['code'] === T_DOUBLE_ARROW) {
            $previousPointer = TokenHelper::findPrevious($phpcsFile, T_OPEN_SHORT_ARRAY, $pointerAfterInlineElseEnd - 1, $inlineThenPointer);
            if ($previousPointer === null) {
                break;
            }
        }
        elseif (ScopeHelper::isInSameScope($phpcsFile, $inlineElsePointer, $pointerAfterInlineElseEnd)) {
            break;
        }
    } while ($pointerAfterInlineElseEnd !== null);
    if ($pointerAfterInlineElseEnd !== null) {
        return TokenHelper::findPreviousEffective($phpcsFile, $pointerAfterInlineElseEnd - 1);
    }
    return TokenHelper::findPreviousEffective($phpcsFile, count($tokens) - 1);
}

API Navigation

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