function DisallowDirectMagicInvokeCallSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $stringPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ PHP/ DisallowDirectMagicInvokeCallSniff.php, line 33
Class
Namespace
SlevomatCodingStandard\Sniffs\PHPCode
public function process(File $phpcsFile, $stringPointer) : void {
$tokens = $phpcsFile->getTokens();
$parenthesisOpenerPointer = TokenHelper::findNextEffective($phpcsFile, $stringPointer + 1);
if ($tokens[$parenthesisOpenerPointer]['code'] !== T_OPEN_PARENTHESIS) {
return;
}
if (strtolower($tokens[$stringPointer]['content']) !== '__invoke') {
return;
}
$objectOperator = TokenHelper::findPreviousEffective($phpcsFile, $stringPointer - 1);
if ($tokens[$objectOperator]['code'] !== T_OBJECT_OPERATOR) {
return;
}
$fix = $phpcsFile->addFixableError('Direct call of __invoke() is disallowed.', $stringPointer, self::CODE_DISALLOWED_DIRECT_MAGIC_INVOKE_CALL);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
FixerHelper::removeBetweenIncluding($phpcsFile, $objectOperator, $parenthesisOpenerPointer - 1);
$phpcsFile->fixer
->endChangeset();
}