function UnusedParameterSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $functionPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Functions/ UnusedParameterSniff.php, line 38
Class
Namespace
SlevomatCodingStandard\Sniffs\FunctionsCode
public function process(File $phpcsFile, $functionPointer) : void {
if (FunctionHelper::isAbstract($phpcsFile, $functionPointer)) {
return;
}
$isSuppressed = SuppressHelper::isSniffSuppressed($phpcsFile, $functionPointer, $this->getSniffName(self::CODE_UNUSED_PARAMETER));
$suppressUseless = true;
$tokens = $phpcsFile->getTokens();
$currentPointer = $tokens[$functionPointer]['parenthesis_opener'] + 1;
while (true) {
$parameterPointer = TokenHelper::findNext($phpcsFile, T_VARIABLE, $currentPointer, $tokens[$functionPointer]['parenthesis_closer']);
if ($parameterPointer === null) {
break;
}
$previousPointer = TokenHelper::findPrevious($phpcsFile, array_merge([
T_COMMA,
], Tokens::$scopeModifiers), $parameterPointer - 1, $tokens[$functionPointer]['parenthesis_opener']);
if ($previousPointer !== null && in_array($tokens[$previousPointer]['code'], Tokens::$scopeModifiers, true)) {
$currentPointer = $parameterPointer + 1;
continue;
}
if (VariableHelper::isUsedInScope($phpcsFile, $functionPointer, $parameterPointer)) {
$currentPointer = $parameterPointer + 1;
continue;
}
if (!$isSuppressed) {
$phpcsFile->addError(sprintf('Unused parameter %s.', $tokens[$parameterPointer]['content']), $parameterPointer, self::CODE_UNUSED_PARAMETER);
}
else {
$suppressUseless = false;
}
$currentPointer = $parameterPointer + 1;
}
if (!$isSuppressed || !$suppressUseless) {
return;
}
$phpcsFile->addError(sprintf('Useless %s %s', SuppressHelper::ANNOTATION, self::NAME), $functionPointer, self::CODE_USELESS_SUPPRESS);
}