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