function DisallowStringExpressionPropertyFetchSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $objectOperatorPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Classes/ DisallowStringExpressionPropertyFetchSniff.php, line 32
Class
Namespace
SlevomatCodingStandard\Sniffs\ClassesCode
public function process(File $phpcsFile, $objectOperatorPointer) : void {
$tokens = $phpcsFile->getTokens();
$curlyBracketOpenerPointer = TokenHelper::findNextEffective($phpcsFile, $objectOperatorPointer + 1);
if ($tokens[$curlyBracketOpenerPointer]['code'] !== T_OPEN_CURLY_BRACKET) {
return;
}
$curlyBracketCloserPointer = $tokens[$curlyBracketOpenerPointer]['bracket_closer'];
if (TokenHelper::findNextExcluding($phpcsFile, T_CONSTANT_ENCAPSED_STRING, $curlyBracketOpenerPointer + 1, $curlyBracketCloserPointer) !== null) {
return;
}
$pointerAfterCurlyBracketCloser = TokenHelper::findNextEffective($phpcsFile, $curlyBracketCloserPointer + 1);
if ($tokens[$pointerAfterCurlyBracketCloser]['code'] === T_OPEN_PARENTHESIS) {
return;
}
if (preg_match('~^(["\'])([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\1$~', $tokens[$curlyBracketOpenerPointer + 1]['content'], $matches) !== 1) {
return;
}
$fix = $phpcsFile->addFixableError('String expression property fetch is disallowed, use identifier property fetch.', $curlyBracketOpenerPointer, self::CODE_DISALLOWED_STRING_EXPRESSION_PROPERTY_FETCH);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
FixerHelper::change($phpcsFile, $curlyBracketOpenerPointer, $curlyBracketCloserPointer, $matches[2]);
$phpcsFile->fixer
->endChangeset();
}