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

Universal/ForeachUniqueAssignment: improve analysis for foreach list assignments #175

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 4, 2022

Universal/ForeachUniqueAssignment: fix some tests

These tests weren't testing the sniff well enough.

Universal/ForeachUniqueAssignment: improve analysis for foreach list assignments

This commit:

  • Prevents "accidentally correct" handling of code like foreach ($data as [$id => $id]), where the first $id is not the key for the foreach assignment, so is not the concern of this sniff.
  • Improves analysis for key vs value when the value is a list assignment.
    Previously, the key and the value would just be compared as found. Now, each individual assignment in the list will be compared against the key.
    Notes: nested list assignment are not (yet) taken into account.

Includes improved and additional tests.

These tests weren't testing the sniff well enough.
…assignments

This commit:
* Prevents "accidentally correct" handling of code like `foreach ($data as [$id => $id])`, where the first `$id` is not the key for the foreach assignment, so is not the concern of this sniff.
* Improves analysis for key vs value when the value is a list assignment.
    Previously, the key and the value would just be compared as found. Now, each individual assignment in the list will be compared against the key.
    Notes: nested list assignment are not (yet) taken into account.

Includes improved and additional tests.
@jrfnl jrfnl added this to the 1.0.0-alpha4 milestone Dec 4, 2022
@jrfnl jrfnl merged commit e7a5b03 into develop Dec 4, 2022
@jrfnl jrfnl deleted the universal/foreachuniqueassignment-improve-list-handling branch December 4, 2022 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant