Skip to content

Squiz.Commenting.FunctionComment.IncorrectTypeHint recognizes generics a part of type hints #746

Open
@Karpec

Description

@Karpec

Describe the bug

Hi, I ran into this issue again. which was already addressed in the old package. Even PR is mentioned as a likely solution. Can we get it into the production version if possible? Thank you for your time :)

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:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. 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)

Operating System [MacOS 15.1.1 - docker container]
PHP version [8.1]
PHP_CodeSniffer version [3.11.1, master]
Standard [Squiz]
Install type [Composer]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions