diff --git a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php index b0b7cafb32..e90ffeddb0 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php @@ -435,6 +435,8 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart) $suggestedTypeHint = 'callable'; } else if (strpos($suggestedName, 'callback') !== false) { $suggestedTypeHint = 'callable'; + } else if (preg_match('/^([^<]+)<[^>]+>$/', $suggestedName, $matches) === 1) { + $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 4fcbb6dbe0..b993190df4 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc @@ -1047,6 +1047,18 @@ public function ignored() { * @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() + /** * When two adjacent pipe symbols are used (by mistake), the sniff should not throw a PHP Fatal error * diff --git a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed index 817630b5ba..af23bcd483 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed @@ -1047,6 +1047,18 @@ public function ignored() { * @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() + /** * When two adjacent pipe symbols are used (by mistake), the sniff should not throw a PHP Fatal error *