Skip to content

Commit 9684318

Browse files
committed
add unit test
1 parent 4afb939 commit 9684318

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
419419

420420
// Check type hint for array and custom type.
421421
$suggestedTypeHint = '';
422-
if (preg_match('/^(.*)<.*>$/', $suggestedTypeHint, $matches)) {
422+
if (preg_match('/^(.*)<.*>$/', $suggestedName, $matches)) {
423423
$suggestedTypeHint = $matches[1];
424424
} else if (strpos($suggestedName, 'array') !== false || substr($suggestedName, -2) === '[]') {
425425
$suggestedTypeHint = 'array';

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,19 @@ public function ignored() {
10421042

10431043
// phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct
10441044

1045-
/**
1045+
/**
10461046
* @return void
10471047
* @throws Exception If any other error occurs. */
10481048
function throwCommentOneLine() {}
1049+
1050+
/**
1051+
* Using generic as a type hint should satisfy a specified object parameter type.
1052+
* @see https://phpstan.org/blog/generics-in-php-using-phpdocs
1053+
*
1054+
* @param Collection<int, string> $values An object with int, string pairs.
1055+
*
1056+
* @return void
1057+
*/
1058+
public function specifiedArray1(Collection $values) {
1059+
1060+
}// end specifiedArray1()

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,19 @@ public function ignored() {
10421042

10431043
// phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct
10441044

1045-
/**
1045+
/**
10461046
* @return void
10471047
* @throws Exception If any other error occurs. */
10481048
function throwCommentOneLine() {}
1049+
1050+
/**
1051+
* Using generic as a type hint should satisfy a specified object parameter type.
1052+
* @see https://phpstan.org/blog/generics-in-php-using-phpdocs
1053+
*
1054+
* @param Collection<int, string> $values An object with int, string pairs.
1055+
*
1056+
* @return void
1057+
*/
1058+
public function specifiedArray1(Collection $values) {
1059+
1060+
}// end specifiedArray1()

0 commit comments

Comments
 (0)