Skip to content

Commit

Permalink
if target is a list, renumber keys after deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed May 1, 2024
1 parent d72143f commit 4e2c1b9
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,24 @@ private function eagerTransform(
// the values array

if (is_array($values) && is_iterable($target)) {
/**
* @psalm-suppress RedundantConditionGivenDocblockType
*/
$isList = is_array($target) && array_is_list($target);

foreach ($target as $key => $value) {
if (!in_array($value, $values, true)) {
unset($target[$key]);
}
}

// renumber array if it is a list

/** @psalm-suppress RedundantConditionGivenDocblockType */
if (is_array($target) && $isList) {
/** @psalm-suppress RedundantFunctionCall */
$target = array_values($target);
}
}

return $target;
Expand Down

0 comments on commit 4e2c1b9

Please sign in to comment.