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.Commenting.FunctionComment.IncorrectTypeHint recognizes generics a part of type hints #746

Open
Karpec opened this issue Nov 28, 2024 · 5 comments · May be fixed by #750
Open

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

Karpec opened this issue Nov 28, 2024 · 5 comments · May be fixed by #750

Comments

@Karpec
Copy link

Karpec commented Nov 28, 2024

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]
@asispts
Copy link

asispts commented Nov 28, 2024

I don't think phpcs is the right tool for this case. This should be handled by a static analyzer.

IMHO, this rule might be deprecated/removed.

@Karpec
Copy link
Author

Karpec commented Nov 29, 2024

Yeah, that's when I stumbled upon it, when leveling up PHPstan to 6. I might turn this rule off eventually, although sometimes it's better to double check

@jrfnl
Copy link
Member

jrfnl commented Dec 2, 2024

@Karpec I'd be happy to have a look at a PR. Maybe @tm1000 would be willing to port their original PR over to this repo (and add some extra tests based on the code sample above) ?

@asispts Well, PHPCS is a static analysis tool ;-)

@Karpec
Copy link
Author

Karpec commented Dec 2, 2024

@jrfnl I'll create a PR for it today, I have time :)

@Karpec
Copy link
Author

Karpec commented Dec 2, 2024

@jrfnl PR created :)

@tm1000 tm1000 linked a pull request Dec 2, 2024 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment