Skip to content

Commit

Permalink
Merge 08b256c into cac6389
Browse files Browse the repository at this point in the history
  • Loading branch information
chadicus committed Jan 4, 2016
2 parents cac6389 + 08b256c commit aa5f95c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/Arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,20 @@ public static function embedInto(array $items, $fieldName, array $destination =
}

foreach ($items as $key => $item) {
if (array_key_exists($key, $destination)) {
if (!is_array($destination[$key])) {
throw new \InvalidArgumentException('a value in $destination was not an array');
}
if (!array_key_exists($key, $destination)) {
$destination[$key] = [$fieldName => $item];
continue;
}

if (!$overwrite && array_key_exists($fieldName, $destination[$key])) {
throw new \Exception('$fieldName key already exists in a $destination array');
}
if (!is_array($destination[$key])) {
throw new \InvalidArgumentException('a value in $destination was not an array');
}

$destination[$key][$fieldName] = $item;
} else {
$destination[$key] = [$fieldName => $item];
if (!$overwrite && array_key_exists($fieldName, $destination[$key])) {
throw new \Exception('$fieldName key already exists in a $destination array');
}

$destination[$key][$fieldName] = $item;
}

return $destination;
Expand Down

0 comments on commit aa5f95c

Please sign in to comment.