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

Breadcrumb

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

function RequireOnlyStandaloneIncrementAndDecrementOperatorsSniff::isStandalone

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

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Operators/RequireOnlyStandaloneIncrementAndDecrementOperatorsSniff.php, line 92

Class

RequireOnlyStandaloneIncrementAndDecrementOperatorsSniff

Namespace

SlevomatCodingStandard\Sniffs\Operators

Code

private function isStandalone(File $phpcsFile, int $instructionStartPointer, int $instructionEndPointer) : bool {
    $tokens = $phpcsFile->getTokens();
    $pointerBeforeInstructionStart = TokenHelper::findPreviousEffective($phpcsFile, $instructionStartPointer - 1);
    if (!in_array($tokens[$pointerBeforeInstructionStart]['code'], [
        T_SEMICOLON,
        T_COLON,
        T_OPEN_CURLY_BRACKET,
        T_CLOSE_CURLY_BRACKET,
        T_OPEN_TAG,
    ], true)) {
        return false;
    }
    $pointerAfterInstructionEnd = TokenHelper::findNextEffective($phpcsFile, $instructionEndPointer + 1);
    if ($tokens[$pointerAfterInstructionEnd]['code'] === T_SEMICOLON) {
        return true;
    }
    if ($tokens[$pointerAfterInstructionEnd]['code'] === T_CLOSE_PARENTHESIS) {
        return array_key_exists('parenthesis_owner', $tokens[$pointerAfterInstructionEnd]) && in_array($tokens[$tokens[$pointerAfterInstructionEnd]['parenthesis_owner']]['code'], [
            T_FOR,
            T_WHILE,
        ], true);
    }
    return false;
}

API Navigation

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