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

Breadcrumb

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

function JumpStatementsSpacingSniff::isOneOfYieldSpecialCases

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

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/JumpStatementsSpacingSniff.php, line 182

Class

JumpStatementsSpacingSniff

Namespace

SlevomatCodingStandard\Sniffs\ControlStructures

Code

private function isOneOfYieldSpecialCases(File $phpcsFile, int $jumpStatementPointer) : bool {
    $tokens = $phpcsFile->getTokens();
    $jumpStatementToken = $tokens[$jumpStatementPointer];
    if ($jumpStatementToken['code'] !== T_YIELD && $jumpStatementToken['code'] !== T_YIELD_FROM) {
        return false;
    }
    // check if yield is used inside parentheses (function call, while, ...)
    if (array_key_exists('nested_parenthesis', $jumpStatementToken)) {
        return true;
    }
    $pointerBefore = TokenHelper::findPreviousEffective($phpcsFile, $jumpStatementPointer - 1);
    // check if yield is used in assignment
    if (in_array($tokens[$pointerBefore]['code'], Tokens::$assignmentTokens, true)) {
        return true;
    }
    // check if yield is used in a return statement
    return $tokens[$pointerBefore]['code'] === T_RETURN;
}

API Navigation

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