Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squiz/FunctionComment: support generics in docblock #750

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@
$suggestedTypeHint = 'callable';
} else if (strpos($suggestedName, 'callback') !== false) {
$suggestedTypeHint = 'callable';
} else if (preg_match('/^([^<]+)<[^>]+>$/', $suggestedName, $matches)) {

Check failure on line 438 in src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php

View workflow job for this annotation

GitHub Actions / PHP: 7.4 (Linux)

Implicit true comparisons prohibited; use === TRUE instead
$suggestedTypeHint = $matches[1];
} else if (in_array($suggestedName, Common::$allowedTypes, true) === false) {
$suggestedTypeHint = $suggestedName;
}
Expand Down
12 changes: 12 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1158,3 +1158,15 @@ function paramVariation3($hasTypeNoComment): void {}
* @return void
*/
function paramVariation4($hasTypehasComment): void {}

/**
* 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<int, string> $values An object with int, string pairs.
*
* @return void
*/
public function genericType(Collection $values) {

}// end genericType()
Original file line number Diff line number Diff line change
Expand Up @@ -1158,3 +1158,15 @@ function paramVariation3($hasTypeNoComment): void {}
* @return void
*/
function paramVariation4($hasTypehasComment): void {}

/**
* 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<int, string> $values An object with int, string pairs.
*
* @return void
*/
public function genericType(Collection $values) {

}// end genericType()
Loading