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

Require value types for nested iterable types #5148

Closed
spawnia opened this issue Jun 8, 2021 · 2 comments
Closed

Require value types for nested iterable types #5148

spawnia opened this issue Jun 8, 2021 · 2 comments

Comments

@spawnia
Copy link

spawnia commented Jun 8, 2021

Feature request

I think it is great that PHPStan requires specification of the value type within iterable types. This feature has prevented a lot of bugs and made our codebase much more understandable. It would be great if it could be taken even further: specifying the value type should also be required for nested iterables.

For the following example, PHPStan should complain that the value type for the nested iterable is missing:

/**
 * @param array<iterable> $bar
 */
function foo(array $bar): void {}

This should extend all the way down if more levels of nesting are used. While it is increasingly more work to write out nested types, I found that those complex parts of our code are also the most error prone.

Did PHPStan help you today? Did it make you happy in any way?

Just yesterday, I was able to find 2 bugs in our codebase by adding a bunch of array shapes 🎉

@ondrejmirtes
Copy link
Member

Thank you for your kind words! :)

This makes total sense, so I implemented it: phpstan/phpstan-src@2f456b9 It requires bleeding edge for now because it has potential to break a lot of code.

If you're getting value out of PHPStan, please consider supporting the development, either by becoming a GitHub sponsor (my personal account, organization account), or by subscribing to PHPStan Pro with your team :) Thanks for considering!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants