From c914bfa72dcef1eb61dc494565b8a147059688f6 Mon Sep 17 00:00:00 2001 From: Benson Lee Date: Wed, 24 Aug 2016 16:43:33 -0700 Subject: [PATCH] Laravel 5.3.2 changes (#19) --- src/Illuminate/Support/Arr.php | 4 ++++ src/Illuminate/Support/Collection.php | 14 +++++--------- tests/Support/SupportCollectionTest.php | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Illuminate/Support/Arr.php b/src/Illuminate/Support/Arr.php index 4af77f6..1931418 100644 --- a/src/Illuminate/Support/Arr.php +++ b/src/Illuminate/Support/Arr.php @@ -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]; diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index c12ab79..63acd68 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -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); } @@ -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); } @@ -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); } /** diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 3f9d5d5..89a8787 100644 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -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(