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

Allow Hash::remove() to remove from ArrayAccess objects #17569

Merged
merged 1 commit into from Apr 30, 2024

Conversation

othercorey
Copy link
Member

@othercorey othercorey commented Jan 29, 2024

closes #17542

@othercorey othercorey added this to the 5.0.6 milestone Jan 29, 2024
@markstory markstory modified the milestones: 5.0.6, 5.0.7 Mar 9, 2024
@ADmad ADmad changed the base branch from 5.x to 5.next March 16, 2024 08:15
@ADmad ADmad modified the milestones: 5.0.7, 5.1.0 Mar 16, 2024
@othercorey othercorey closed this Apr 14, 2024
@othercorey othercorey deleted the hash-remove-object branch April 14, 2024 09:58
@ADmad
Copy link
Member

ADmad commented Apr 14, 2024

@othercorey Didn't my update get this working as expected?

@othercorey
Copy link
Member Author

Oh, maybe? I didn't notice you pushed. I made similar changes and kept running into static analysis errors due to remove() accepting ArrayAccess as a parameter.

@othercorey othercorey restored the hash-remove-object branch April 14, 2024 13:00
@othercorey othercorey reopened this Apr 14, 2024
@ADmad
Copy link
Member

ADmad commented Apr 14, 2024

My bad, I should have left a comment after updating. I'll look into the static analysis errors.

@ADmad ADmad force-pushed the hash-remove-object branch 3 times, most recently from 5b3bfe3 to 12afbea Compare April 14, 2024 15:26
@ADmad ADmad marked this pull request as ready for review April 14, 2024 15:27
* @param list<string> $path The path to work on.
* @param mixed $values The values to insert when doing inserts.
* @return \ArrayAccess|array data.
* @psalm-return (T is array ? array : \ArrayAccess)
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is what I was missing. I was expecting T to evaluate to a specific type in the above union.

@@ -415,6 +420,10 @@ public static function remove(ArrayAccess|array $data, string $path): ArrayAcces

[$token, $conditions] = self::_splitConditions($token);

if (!is_iterable($data)) {
throw new CakeException('Cannot use path tokens of type `{}` or `[]` for non-iterable objects.');
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, this is why I closed the PR originally, I wasn't sure if we had to add ArrayAccess-only iteration and logic.

@othercorey
Copy link
Member Author

I think this change requires changing insert() to match.

@othercorey othercorey force-pushed the hash-remove-object branch 2 times, most recently from 8492d73 to 3ed3aed Compare April 26, 2024 04:43
@othercorey
Copy link
Member Author

@ADmad Added support to insert()

@ADmad
Copy link
Member

ADmad commented Apr 26, 2024

LGTM. The psalm errors can be ignored, the iterable check seems to confuse it.

@markstory markstory merged commit 6e7243b into 5.next Apr 30, 2024
10 checks passed
@markstory markstory deleted the hash-remove-object branch April 30, 2024 20:38
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.

None yet

3 participants