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

Can't override mixed to iterable #6564

Closed
tomasfejfar opened this issue Feb 4, 2022 · 4 comments
Closed

Can't override mixed to iterable #6564

tomasfejfar opened this issue Feb 4, 2022 · 4 comments

Comments

@tomasfejfar
Copy link
Contributor

Bug report

When a variable is mixed I can't make it iterable. The "iterability" is checked by outside factors. In my particular case it's where I need to iterate the value in Symfony validator. And the value's iterability is determined by \Symfony\Component\Validator\Constraints\Choice::$multiple (https://github.com/symfony/validator/blob/5.4/Constraints/ChoiceValidator.php#L67).

Code snippet that reproduces the problem

https://phpstan.org/r/ee58cb2e-38b4-4fb4-82d9-3250a9691deb

Expected output

Ideally I would hint that inside the condition the variable contains mixed[]

@staabm
Copy link
Contributor

staabm commented Feb 4, 2022

Couldn't you just check with is_iterable beforehand?

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@b6bbbaf

@tomasfejfar
Copy link
Contributor Author

No errors now on bleeding edge! Thanks! :)

@staabm I could, but I tend to not add code for static analysis purposes. The code already does enough checks to make sure it's iterable. It just has been hard to tell PHPStan. In such cases my heuristic is to not add code, but rather a typehint. In cases where I (the developer) know that the variable is indeed iterable based on business rules, but I make no effort to enforce it - that's where I'll add the code.

@github-actions
Copy link

github-actions bot commented Mar 9, 2022

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 Mar 9, 2022
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

3 participants