Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Commit

Permalink
Fixed problems with concat
Browse files Browse the repository at this point in the history
  • Loading branch information
italolelis committed Jun 3, 2016
1 parent 4312095 commit 0f7fe19
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
25 changes: 0 additions & 25 deletions src/Traits/CommonMutableContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,31 +144,6 @@ public function replace($iterable)
return $this;
}

private function concatRecurse($array, $array1)
{
$merged = $array;

foreach ($array1 as $key => $value) {
$isValid = function ($value) {
return (is_array($value) || $value instanceof \Traversable);
};

if (($isValid($value) && isset($merged[$key])) && $isValid($merged[$key])) {
$merged[$key] = $this->concatRecurse($merged[$key], $value);
} else {
if (is_numeric($key)) {
if (!isset($merged[$key])) {
$merged[$key] = $value;
}
} else {
$merged[$key] = $value;
}
}
}

return $merged;
}

private function replaceRecurse($array, $array1)
{
foreach ($array1 as $key => $value) {
Expand Down
23 changes: 22 additions & 1 deletion src/Traits/StrictIterableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function slice($start, $length)

return $res;
}

/**
* {@inheritDoc}
* @return $this
Expand Down Expand Up @@ -249,4 +249,25 @@ public function reduce(callable $callback, $initial = null)

return $initial;
}

private function concatRecurse($array, $array1)
{
$merged = $array;

foreach ($array1 as $key => $value) {
$isValid = function ($value) {
return (is_array($value) || $value instanceof \Traversable);
};

if (($isValid($value) && isset($merged[$key])) && $isValid($merged[$key])) {
$merged[$key] = $this->concatRecurse($merged[$key], $value);
} else {
if (!in_array($value, $merged->toArray())) {
$merged[] = $value;
}
}
}

return $merged;
}
}
21 changes: 20 additions & 1 deletion src/Traits/StrictKeyedIterableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function slice($start, $lenght)

return $res;
}

public function first()
{
foreach ($this as $v) {
Expand Down Expand Up @@ -234,4 +234,23 @@ public function concatAll()

return $results;
}

private function concatRecurse($array, $array1)
{
$merged = $array;

foreach ($array1 as $key => $value) {
$isValid = function ($value) {
return (is_array($value) || $value instanceof \Traversable);
};

if (($isValid($value) && isset($merged[$key])) && $isValid($merged[$key])) {
$merged[$key] = $this->concatRecurse($merged[$key], $value);
} else {
$merged[$key] = $value;
}
}

return $merged;
}
}

0 comments on commit 0f7fe19

Please sign in to comment.