diff --git a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php index ba3e1710f0..e0862e3859 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php @@ -425,6 +425,8 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart) $suggestedTypeHint = 'callable'; } else if (strpos($suggestedName, 'callback') !== false) { $suggestedTypeHint = 'callable'; + } else if (preg_match('/^([^<]+)<[^>]+>$/', $suggestedName, $matches)) { + $suggestedTypeHint = $matches[1]; } else if (in_array($suggestedName, Common::$allowedTypes, true) === false) { $suggestedTypeHint = $suggestedName; } diff --git a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc index 4f59f60b71..dd964dc226 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc @@ -1042,7 +1042,19 @@ public function ignored() { // phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct -/** +/** * @return void * @throws Exception If any other error occurs. */ function throwCommentOneLine() {} + +/** + * Using generic as a type hint should satisfy a specified object parameter type. + * @see https://phpstan.org/blog/generics-in-php-using-phpdocs + * + * @param Collection $values An object with int, string pairs. + * + * @return void + */ +public function genericType(Collection $values) { + +}// end genericType() diff --git a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed index 21a4103eb5..ffb67e8c9a 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed @@ -1042,7 +1042,19 @@ public function ignored() { // phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct -/** +/** * @return void * @throws Exception If any other error occurs. */ function throwCommentOneLine() {} + +/** + * Using generic as a type hint should satisfy a specified object parameter type. + * @see https://phpstan.org/blog/generics-in-php-using-phpdocs + * + * @param Collection $values An object with int, string pairs. + * + * @return void + */ +public function genericType(Collection $values) { + +}// end genericType()