Skip to content

Commit

Permalink
Removed generator in favour of array
Browse files Browse the repository at this point in the history
  • Loading branch information
zmitic committed Apr 12, 2021
1 parent 38fc815 commit 249bd83
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Accessor/CollectionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private function getExtraValues(callable $compare, array $originalValues, array
/** @var array<array-key, object|array> $extraValues */
$extraValues = [];
foreach ($submittedValues as $key => $value) {
$searchKey = array_search($value, $originalValues, true);
// $searchKey = array_search($value, $originalValues, true);
$searchKey = $this->search($compare, $key, $value, $originalValues);

if (false === $searchKey || $key !== $searchKey || !$this->isEqual($compare, $originalValues[$searchKey], $value)) {
$extraValues[$key] = $value;
Expand All @@ -115,6 +116,17 @@ private function getExtraValues(callable $compare, array $originalValues, array
return $extraValues;
}

private function search(callable $compare, $key, $value, $originalValues)
{
foreach ($originalValues as $originalKey => $originalValue) {
if ($value && $originalValue && $compare($value, $originalValue, $key, $originalKey) === true) {
return $key;
}
}

return false;
}

private function extractRemoveEntryFromCollection(FormInterface $form): ?\Closure
{
foreach ($form as $child) {
Expand Down

0 comments on commit 249bd83

Please sign in to comment.