diff --git a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php index b0b7cafb32..3531758a4d 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php @@ -311,7 +311,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart) $commentLines = []; if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { $matches = []; - preg_match('/([^$&.]+)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches); + preg_match('/((?:(?![$.]|&(?=\$)).)*)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches); if (empty($matches) === false) { $typeLen = strlen($matches[1]); @@ -323,7 +323,10 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart) } } - if (isset($matches[2]) === true) { + if ($tokens[($tag + 2)]['content'][0] === '$') { + $error = 'Missing parameter type'; + $phpcsFile->addError($error, $tag, 'MissingParamType'); + } else if (isset($matches[2]) === true) { $var = $matches[2]; $varLen = strlen($var); if ($varLen > $maxVar) { @@ -366,9 +369,6 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart) $phpcsFile->addError($error, $tag, 'MissingParamComment'); $commentLines[] = ['comment' => '']; }//end if - } else if ($tokens[($tag + 2)]['content'][0] === '$') { - $error = 'Missing parameter type'; - $phpcsFile->addError($error, $tag, 'MissingParamType'); } else { $error = 'Missing parameter name'; $phpcsFile->addError($error, $tag, 'MissingParamName'); diff --git a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc index 4fcbb6dbe0..79060f4fe7 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc @@ -1158,3 +1158,12 @@ function paramVariation3($hasTypeNoComment): void {} * @return void */ function paramVariation4($hasTypehasComment): void {} + +/** + * @param (Foo&Bar)|null $a Comment. + * @return void + */ +public function setTranslator($a): void +{ + $this->translator = $translator; +} diff --git a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed index 817630b5ba..76fa862ab0 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed @@ -1158,3 +1158,12 @@ function paramVariation3($hasTypeNoComment): void {} * @return void */ function paramVariation4($hasTypehasComment): void {} + +/** + * @param (Foo&Bar)|null $a Comment. + * @return void + */ +public function setTranslator($a): void +{ + $this->translator = $translator; +}