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
Conversation
18c87fd
to
f6143a1
Compare
@othercorey Didn't my update get this working as expected? |
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. |
My bad, I should have left a comment after updating. I'll look into the static analysis errors. |
5b3bfe3
to
12afbea
Compare
src/Utility/Hash.php
Outdated
* @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) |
There was a problem hiding this comment.
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.
src/Utility/Hash.php
Outdated
@@ -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.'); | |||
} |
There was a problem hiding this comment.
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.
I think this change requires changing insert() to match. |
8492d73
to
3ed3aed
Compare
@ADmad Added support to insert() |
LGTM. The psalm errors can be ignored, the iterable check seems to confuse it. |
3ed3aed
to
05cd92e
Compare
05cd92e
to
7129958
Compare
closes #17542