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
Namespace
SlevomatCodingStandard\Sniffs\ControlStructuresCode
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;
}