From daf6e093355c286948abe81fabae1dc5dab3ebcc Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 8 Jun 2023 13:39:56 +0100 Subject: [PATCH] Avoid claiming param is missing when only prefixed --- .../Sniffs/Commenting/FunctionCommentSniff.php | 18 ++++++++++-------- .../Commenting/FunctionCommentUnitTest.php | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php index 3293228bba..03fee61290 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php @@ -554,15 +554,17 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart) $realName = $realParams[$pos]['name']; $paramVarName = $param['var']; - if ($realParams[$pos]['pass_by_reference'] === true && $param['var'][0] === '&') { - // When passed by reference, the variable name in $realParams does not - // have a leading '&'. There is no guidance in PSR-19 to say if the - // docblock SHOULD or SHOULD NOT also have a leading '&'. Therefore, - // this sniff remains agnostic in this case. - $paramVarName = substr($param['var'], 1); - + if ($param['var'][0] === '&') { // This makes sure that the 'MissingParamTag' check won't throw a false positive. - $foundParams[(count($foundParams) - 1)] = $paramVarName; + $foundParams[(count($foundParams) - 1)] = substr($param['var'], 1); + + if ($realParams[$pos]['pass_by_reference'] === true) { + // When passed by reference, the variable name in $realParams does not + // have a leading '&'. There is no guidance in PSR-19 to say if the + // docblock SHOULD or SHOULD NOT also have a leading '&'. Therefore, + // this sniff remains agnostic in this case. + $paramVarName = substr($param['var'], 1); + } } if ($realName !== $paramVarName) { diff --git a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php index 7f15c86c1a..4fbd47dd95 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php @@ -115,7 +115,7 @@ public function getErrorList() 1004 => 2, 1006 => 1, 1029 => 1, - 1050 => 2, + 1050 => 1, 1062 => 1, 1063 => 1, 1072 => 4,