Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Laravel 5.3.2 changes (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
besologic authored Aug 24, 2016
1 parent 9e83e61 commit c914bfa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ public static function has($array, $keys)
foreach ($keys as $key) {
$subKeyArray = $array;

if (static::exists($array, $key)) {
continue;
}

foreach (explode('.', $key) as $segment) {
if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) {
$subKeyArray = $subKeyArray[$segment];
Expand Down
14 changes: 5 additions & 9 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ public function map(callable $callback)
* @param callable $callback
* @return static
*/
public function mapToAssoc(callable $callback)
public function mapWithKeys(callable $callback)
{
return $this->flatMap($callback);
}
Expand Down Expand Up @@ -947,13 +947,9 @@ public function sort(callable $callback = null)
{
$items = $this->items;

$callback ? uasort($items, $callback) : uasort($items, function ($a, $b) {
if ($a == $b) {
return 0;
}

return ($a < $b) ? -1 : 1;
});
$callback
? uasort($items, $callback)
: asort($items);

return new static($items);
}
Expand Down Expand Up @@ -1236,7 +1232,7 @@ public function count()
*/
public function toBase()
{
return is_subclass_of($this, self::class) ? new self($this) : $this;
return new self($this);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,14 +895,14 @@ public function testFlatMap()
$this->assertEquals(['programming', 'basketball', 'music', 'powerlifting'], $data->all());
}

public function testMapToAssoc()
public function testMapWithKeys()
{
$data = new Collection([
['name' => 'Blastoise', 'type' => 'Water', 'idx' => 9],
['name' => 'Charmander', 'type' => 'Fire', 'idx' => 4],
['name' => 'Dragonair', 'type' => 'Dragon', 'idx' => 148],
]);
$data = $data->mapToAssoc(function ($pokemon) {
$data = $data->mapWithKeys(function ($pokemon) {
return [$pokemon['name'] => $pokemon['type']];
});
$this->assertEquals(
Expand Down

0 comments on commit c914bfa

Please sign in to comment.