Skip to content

Lists::getAssignments(): improve the return value #129

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

Merged
merged 1 commit into from
Apr 1, 2020

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 1, 2020

⚠️ BREAKING CHANGE ⚠️

In the initial commit, the Lists::getAssignments() method would have three different arrays as potential output.

  1. An array with just the raw and is_empty keys for an empty list item.
  2. An array with the above + detailed information about the assignments for non-keyed list items.
  3. An array with the above + detail information about the keys found for keyed list items.

This meant that - aside from for the raw and is_empty keys -, a dev looping over the list items would always need to do an isset() check for each array index before the value could be compared or used.

That made the method return value fiddly to work with.

In this commit, the above three different arrays is now reduced to two different arrays (type 2 and 3) with either an empty string or false as the default value for all keys.

Additionally:

  • The nested_list index key has been renamed to is_nested_list to make it clearer that this will be a boolean value and not the detailed information about the nested list.
  • And while this will rarely be relevant for sniffs implementing this method, the order of the array indexes in the return array has also been adjusted.

Includes updated unit tests.

⚠️ **BREAKING CHANGE** ⚠️

In the initial commit, the `Lists::getAssignments()` method would have three different arrays as potential output.
1. An array with just the `raw` and `is_empty` keys for an empty list item.
2. An array with the above + detailed information about the assignments for non-keyed list items.
3. An array with the above + detail information about the keys found for keyed list items.

This meant that - aside from for the `raw` and `is_empty` keys -, a dev looping over the list items would always need to do an `isset()` check for each array index before the value could be compared or used.

That made the method return value fiddly to work with.

In this commit, the above three different arrays is now reduced to two different arrays (type 2 and 3) with either an empty string or `false` as the default value for all keys.

Additionally:
* The `nested_list` index key has been renamed to `is_nested_list` to make it clearer that this will be a boolean value and not the detailed information about the nested list.
* And while this will rarely be relevant for sniffs implementing this method, the order of the array indexes in the return array has also been adjusted.

Includes updated unit tests.
@jrfnl jrfnl added this to the 1.0.0 milestone Apr 1, 2020
@jrfnl jrfnl merged commit e6d1c7f into develop Apr 1, 2020
@jrfnl jrfnl deleted the lists/getassignments-improve-return-value branch April 1, 2020 01:05
@jrfnl jrfnl modified the milestones: 1.0.0, 1.0.0-alpha3 May 1, 2020
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.

1 participant