Skip to content

Conversation

@borkweb
Copy link
Member

@borkweb borkweb commented Dec 18, 2024

I found a bug in one of the methods and then started down the road of creating tests for all of the methods and found a few more bugs!

Most of the line count changes come from the tests.

This pull request includes various changes to the src/Arrays/Arr.php file, as well as adding new unit tests. The main focus is on improving array manipulation methods, adding new functionalitys, and enhancing test coverage.

Improvements and Bug Fixes in Array Manipulation:

  • src/Arrays/Arr.php: Modified several methods to improve functionality and fix bugs. Notable changes include:
    • add: Ensured the method handles dot notation keys and returns the modified array.
    • dot: Removed the condition that checks for empty arrays, allowing the method to handle all arrays.
    • except: Updated to return a new array after forgetting specified keys.
    • exists: Simplified the method by using the has method.
    • flatten: Enhanced to preserve string keys and handle nested arrays more effectively.
    • forget: Reworked to handle dot notation keys and nested arrays correctly.
    • get: Improved to throw an exception if the variable is not accessible and handle dot notation keys.
    • has: Enhanced to handle dot notation keys and check for key existence more efficiently.
    • list_to_array: Fixed the regular expression to handle separators correctly.
    • merge_recursive: Added support for merging arrays with numeric keys.
    • recursive_ksort: Ensured numeric keys are sorted naturally.
    • set: Changed to throw an exception if an invalid key is provided.
    • sort_by_priority: Added validation to ensure the input is an array.
    • stringify_keys: Simplified the method to generate unique prefixes.
    • strpos: Added filtering for valid needles.
    • to_list: Improved handling of null and empty lists.

I found a bug in one of the methods and then started down the road of creating tests for all of the methods and found a few more bugs!

Most of the changes in here are the tests.
@borkweb borkweb requested a review from bordoni December 18, 2024 19:19
@borkweb borkweb changed the title A handful of fixes for various methods Fixes for add, undot, flatten, forget, get, merge_recursive, etc Dec 18, 2024
@borkweb borkweb changed the title Fixes for add, undot, flatten, forget, get, merge_recursive, etc Fixes for add, flatten, forget, get, merge_recursive, etc Dec 18, 2024
Copy link
Contributor

@tarecord tarecord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the changes in Arr look good. I breezed over the tests, if they're passing I'm good with it 👍🏼

Comment on lines -1072 to +1103
_doing_it_wrong( __FUNCTION__, esc_html( $error ), '4.3' );
break;
throw new \InvalidArgumentException( $error );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@borkweb borkweb merged commit e276124 into main Dec 18, 2024
2 checks passed
@borkweb borkweb deleted the fix/tests-and-bugfixes branch December 18, 2024 20:27
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.

3 participants