Skip to content

Commit

Permalink
Avoid claiming param is missing when only prefixed
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Jun 8, 2023
1 parent d646cde commit daf6e09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getErrorList()
1004 => 2,
1006 => 1,
1029 => 1,
1050 => 2,
1050 => 1,
1062 => 1,
1063 => 1,
1072 => 4,
Expand Down

0 comments on commit daf6e09

Please sign in to comment.