-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
Describe the bug
The Squiz.Commenting.FunctionComment.IncorrectTypeHint
sniff gives me an error that I should include the generics part <>
in type hints, which is not valid PHP code.
It works good with @return
or array
for @params
, but it definitely has a problem with other types as in the code sample below.
As Laravel 9 and PhpStorm 2022.1 have recently supported generics, I think the sniff's problem can be a barrier for their users.
Code sample
use Illuminate\Support\Collection;
/**
* @param array<int, string> $array
* @param iterable<string> $iterable
* @param int<0, 100> $int
* @param \Illuminate\Support\Collection<int, string> $collection
*
* @return \Illuminate\Support\Collection<int, string>
*/
function test(
array $array,
iterable $iterable,
int $int,
Collection $collection,
): Collection {
return new Collection();
}
Custom ruleset
N/A
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above... - Run
phpcs test.php ...
- See error message displayed
15 | ERROR | [ ] Expected type hint "iterable<string>"; found "iterable" for $iterable (Squiz.Commenting.FunctionComment.IncorrectTypeHint)
15 | ERROR | [ ] Expected type hint "int<0, 100>"; found "int" for $int (Squiz.Commenting.FunctionComment.IncorrectTypeHint)
15 | ERROR | [ ] Expected type hint "\Illuminate\Support\Collection<int, string>"; found "Collection" for $collection
| | (Squiz.Commenting.FunctionComment.IncorrectTypeHint)
Expected behavior
Errors should not occur with generics <>
, just like how it works for an array.
Versions (please complete the following information):
- OS: Windows 10 WSL 2 Ubuntu 18.04
- PHP: 8.0
- PHPCS: 3.6.2
- Standard: Squiz
Starfox64
Metadata
Metadata
Assignees
Labels
No labels