function ReferenceSpacingSniff::isReference
1 call to ReferenceSpacingSniff::isReference()
- ReferenceSpacingSniff::process in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ PHP/ ReferenceSpacingSniff.php - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ PHP/ ReferenceSpacingSniff.php, line 88
Class
Namespace
SlevomatCodingStandard\Sniffs\PHPCode
private function isReference(File $phpcsFile, int $referencePointer) : bool {
$tokens = $phpcsFile->getTokens();
$previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $referencePointer - 1);
if (in_array($tokens[$previousPointer]['code'], TokenHelper::$functionTokenCodes, true)) {
return true;
}
$previousParenthesisOpenerPointer = TokenHelper::findPrevious($phpcsFile, T_OPEN_PARENTHESIS, $referencePointer - 1);
if ($previousParenthesisOpenerPointer !== null && $tokens[$previousParenthesisOpenerPointer]['parenthesis_closer'] > $referencePointer) {
if (array_key_exists('parenthesis_owner', $tokens[$previousParenthesisOpenerPointer])) {
$parenthesisOwnerPointer = $tokens[$previousParenthesisOpenerPointer]['parenthesis_owner'];
if (in_array($tokens[$parenthesisOwnerPointer]['code'], TokenHelper::$functionTokenCodes, true)) {
return true;
}
}
$pointerBeforeParenthesisOpener = TokenHelper::findPreviousEffective($phpcsFile, $previousParenthesisOpenerPointer - 1);
if ($pointerBeforeParenthesisOpener !== null && $tokens[$pointerBeforeParenthesisOpener]['code'] === T_USE) {
return true;
}
}
/** @var int $variableStartPointer */
$variableStartPointer = TokenHelper::findNextEffective($phpcsFile, $referencePointer + 1);
$variableEndPointer = IdentificatorHelper::findEndPointer($phpcsFile, $variableStartPointer);
if ($variableEndPointer === null) {
return false;
}
$previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $referencePointer - 1);
return in_array($tokens[$previousPointer]['code'], [
T_EQUAL,
T_DOUBLE_ARROW,
T_OPEN_SHORT_ARRAY,
T_COMMA,
T_AS,
], true);
}