Skip to content

Commit 43b5238

Browse files
committed
Merge branch 'master' into 3.0
2 parents 2b904e1 + 9ccd5a7 commit 43b5238

File tree

1 file changed

+110
-74
lines changed

1 file changed

+110
-74
lines changed

src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php

+110-74
Original file line numberDiff line numberDiff line change
@@ -444,43 +444,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
444444
$foundParams[] = $param['var'];
445445

446446
// Check number of spaces after the type.
447-
$spaces = ($maxType - strlen($param['type']) + 1);
448-
if ($param['type_space'] !== $spaces) {
449-
$error = 'Expected %s spaces after parameter type; %s found';
450-
$data = array(
451-
$spaces,
452-
$param['type_space'],
453-
);
454-
455-
$fix = $phpcsFile->addFixableError($error, $param['tag'], 'SpacingAfterParamType', $data);
456-
if ($fix === true) {
457-
$phpcsFile->fixer->beginChangeset();
458-
459-
$content = $param['type'];
460-
$content .= str_repeat(' ', $spaces);
461-
$content .= $param['var'];
462-
$content .= str_repeat(' ', $param['var_space']);
463-
$content .= $param['commentLines'][0]['comment'];
464-
$phpcsFile->fixer->replaceToken(($param['tag'] + 2), $content);
465-
466-
// Fix up the indent of additional comment lines.
467-
foreach ($param['commentLines'] as $lineNum => $line) {
468-
if ($lineNum === 0
469-
|| $param['commentLines'][$lineNum]['indent'] === 0
470-
) {
471-
continue;
472-
}
473-
474-
$newIndent = ($param['commentLines'][$lineNum]['indent'] + $spaces - $param['type_space']);
475-
$phpcsFile->fixer->replaceToken(
476-
($param['commentLines'][$lineNum]['token'] - 1),
477-
str_repeat(' ', $newIndent)
478-
);
479-
}
480-
481-
$phpcsFile->fixer->endChangeset();
482-
}//end if
483-
}//end if
447+
$this->checkSpacingAfterParamType($phpcsFile, $param, $maxType);
484448

485449
// Make sure the param name is correct.
486450
if (isset($realParams[$pos]) === true) {
@@ -513,43 +477,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
513477
}
514478

515479
// Check number of spaces after the var name.
516-
$spaces = ($maxVar - strlen($param['var']) + 1);
517-
if ($param['var_space'] !== $spaces) {
518-
$error = 'Expected %s spaces after parameter name; %s found';
519-
$data = array(
520-
$spaces,
521-
$param['var_space'],
522-
);
523-
524-
$fix = $phpcsFile->addFixableError($error, $param['tag'], 'SpacingAfterParamName', $data);
525-
if ($fix === true) {
526-
$phpcsFile->fixer->beginChangeset();
527-
528-
$content = $param['type'];
529-
$content .= str_repeat(' ', $param['type_space']);
530-
$content .= $param['var'];
531-
$content .= str_repeat(' ', $spaces);
532-
$content .= $param['commentLines'][0]['comment'];
533-
$phpcsFile->fixer->replaceToken(($param['tag'] + 2), $content);
534-
535-
// Fix up the indent of additional comment lines.
536-
foreach ($param['commentLines'] as $lineNum => $line) {
537-
if ($lineNum === 0
538-
|| $param['commentLines'][$lineNum]['indent'] === 0
539-
) {
540-
continue;
541-
}
542-
543-
$newIndent = ($param['commentLines'][$lineNum]['indent'] + $spaces - $param['var_space']);
544-
$phpcsFile->fixer->replaceToken(
545-
($param['commentLines'][$lineNum]['token'] - 1),
546-
str_repeat(' ', $newIndent)
547-
);
548-
}
549-
550-
$phpcsFile->fixer->endChangeset();
551-
}//end if
552-
}//end if
480+
$this->checkSpacingAfterParamName($phpcsFile, $param, $maxVar);
553481

554482
// Param comments must start with a capital letter and end with the full stop.
555483
if (preg_match('/^(\p{Ll}|\P{L})/u', $param['comment']) === 1) {
@@ -580,4 +508,112 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
580508
}//end processParams()
581509

582510

511+
/**
512+
* Check the spacing after the type of a parameter.
513+
*
514+
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
515+
* @param array $param The parameter to be checked.
516+
* @param int $maxType The maxlength of the longest parameter type.
517+
* @param int $spacing The number of spaces to add after the type.
518+
*
519+
* @return void
520+
*/
521+
protected function checkSpacingAfterParamType(PHP_CodeSniffer_File $phpcsFile, $param, $maxType, $spacing = 1)
522+
{
523+
// Check number of spaces after the type.
524+
$spaces = ($maxType - strlen($param['type']) + $spacing);
525+
if ($param['type_space'] !== $spaces) {
526+
$error = 'Expected %s spaces after parameter type; %s found';
527+
$data = array(
528+
$spaces,
529+
$param['type_space'],
530+
);
531+
532+
$fix = $phpcsFile->addFixableError($error, $param['tag'], 'SpacingAfterParamType', $data);
533+
if ($fix === true) {
534+
$phpcsFile->fixer->beginChangeset();
535+
536+
$content = $param['type'];
537+
$content .= str_repeat(' ', $spaces);
538+
$content .= $param['var'];
539+
$content .= str_repeat(' ', $param['var_space']);
540+
$content .= $param['commentLines'][0]['comment'];
541+
$phpcsFile->fixer->replaceToken(($param['tag'] + 2), $content);
542+
543+
// Fix up the indent of additional comment lines.
544+
foreach ($param['commentLines'] as $lineNum => $line) {
545+
if ($lineNum === 0
546+
|| $param['commentLines'][$lineNum]['indent'] === 0
547+
) {
548+
continue;
549+
}
550+
551+
$newIndent = ($param['commentLines'][$lineNum]['indent'] + $spaces - $param['type_space']);
552+
$phpcsFile->fixer->replaceToken(
553+
($param['commentLines'][$lineNum]['token'] - 1),
554+
str_repeat(' ', $newIndent)
555+
);
556+
}
557+
558+
$phpcsFile->fixer->endChangeset();
559+
}//end if
560+
}//end if
561+
562+
}//end checkSpacingAfterParamType()
563+
564+
565+
/**
566+
* Check the spacing after the name of a parameter.
567+
*
568+
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
569+
* @param array $param The parameter to be checked.
570+
* @param int $maxVar The maxlength of the longest parameter name.
571+
* @param int $spacing The number of spaces to add after the type.
572+
*
573+
* @return void
574+
*/
575+
protected function checkSpacingAfterParamName(PHP_CodeSniffer_File $phpcsFile, $param, $maxVar, $spacing = 1)
576+
{
577+
// Check number of spaces after the var name.
578+
$spaces = ($maxVar - strlen($param['var']) + $spacing);
579+
if ($param['var_space'] !== $spaces) {
580+
$error = 'Expected %s spaces after parameter name; %s found';
581+
$data = array(
582+
$spaces,
583+
$param['var_space'],
584+
);
585+
586+
$fix = $phpcsFile->addFixableError($error, $param['tag'], 'SpacingAfterParamName', $data);
587+
if ($fix === true) {
588+
$phpcsFile->fixer->beginChangeset();
589+
590+
$content = $param['type'];
591+
$content .= str_repeat(' ', $param['type_space']);
592+
$content .= $param['var'];
593+
$content .= str_repeat(' ', $spaces);
594+
$content .= $param['commentLines'][0]['comment'];
595+
$phpcsFile->fixer->replaceToken(($param['tag'] + 2), $content);
596+
597+
// Fix up the indent of additional comment lines.
598+
foreach ($param['commentLines'] as $lineNum => $line) {
599+
if ($lineNum === 0
600+
|| $param['commentLines'][$lineNum]['indent'] === 0
601+
) {
602+
continue;
603+
}
604+
605+
$newIndent = ($param['commentLines'][$lineNum]['indent'] + $spaces - $param['var_space']);
606+
$phpcsFile->fixer->replaceToken(
607+
($param['commentLines'][$lineNum]['token'] - 1),
608+
str_repeat(' ', $newIndent)
609+
);
610+
}
611+
612+
$phpcsFile->fixer->endChangeset();
613+
}//end if
614+
}//end if
615+
616+
}//end checkSpacingAfterParamName()
617+
618+
583619
}//end class

0 commit comments

Comments
 (0)