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

Only allow unused values in associative foreach loops with option #167

Merged
merged 6 commits into from
Apr 19, 2020

Conversation

sirbrillig
Copy link
Owner

@sirbrillig sirbrillig commented Apr 19, 2020

Previously the (by default enabled) option allowUnusedForeachVariables ignored all variables created in a foreach statement.

The idea behind this option is that some foreach statements wish to use the key of an associative array and ignore the value, and doing so requires creating an unused value variable.

The idea and the implementation were not in accordance, however. This PR changes the meaning of the option from "do not mark any unused variable created in a foreach statement" to the more correct "do not mark any unused value variable created in a foreach statement on an associative array".

Fixes #166

@sirbrillig sirbrillig merged commit 84ddbb3 into master Apr 19, 2020
@sirbrillig sirbrillig deleted the unused-foreach-values-only branch April 19, 2020 16:48
sirbrillig added a commit that referenced this pull request May 25, 2020
* Fix syntax of ThisWithinNestedClosedScopeFixture

Weird that I never noticed that before.

* Update tests to mark unused keys even with allowUnusedForeachVariables

* Update description of allowUnusedForeachVariables to be accurate

This makes it clear that it only operates on the values of a `key =>
value` expression.

* Adjust more tests which use default allowUnusedForeachVariables

* Only allow unused values in associative foreach loops with option

* Fix unused foreach keys in sniff and helpers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allowUnusedForeachVariables should be for values only
1 participant