function FunctionCommentSniff::checkSpacingAfterParamName
Check the spacing after the name of a parameter.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
array $param The parameter to be checked.:
int $maxVar The maxlength of the longest parameter name.:
int $spacing The number of spaces to add after the type.:
Return value
void
1 call to FunctionCommentSniff::checkSpacingAfterParamName()
- FunctionCommentSniff::processParams in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Commenting/ FunctionCommentSniff.php - Process the function parameter comments.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Commenting/ FunctionCommentSniff.php, line 715
Class
Namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\CommentingCode
protected function checkSpacingAfterParamName(File $phpcsFile, $param, $maxVar, $spacing = 1) {
// Check number of spaces after the var name.
$spaces = $maxVar - strlen($param['var']) + $spacing;
if ($param['var_space'] !== $spaces) {
$error = 'Expected %s spaces after parameter name; %s found';
$data = [
$spaces,
$param['var_space'],
];
$fix = $phpcsFile->addFixableError($error, $param['tag'], 'SpacingAfterParamName', $data);
if ($fix === true) {
$phpcsFile->fixer
->beginChangeset();
$content = $param['type'];
$content .= str_repeat(' ', $param['type_space']);
$content .= $param['var'];
$content .= str_repeat(' ', $spaces);
$content .= $param['commentLines'][0]['comment'];
$phpcsFile->fixer
->replaceToken($param['tag'] + 2, $content);
// Fix up the indent of additional comment lines.
foreach ($param['commentLines'] as $lineNum => $line) {
if ($lineNum === 0 || $param['commentLines'][$lineNum]['indent'] === 0) {
continue;
}
$diff = $param['var_space'] - $spaces;
$newIndent = $param['commentLines'][$lineNum]['indent'] - $diff;
if ($newIndent <= 0) {
continue;
}
$phpcsFile->fixer
->replaceToken($param['commentLines'][$lineNum]['token'] - 1, str_repeat(' ', $newIndent));
}
$phpcsFile->fixer
->endChangeset();
}
//end if
}
//end if
}