From 2463e41f396fc50bce764f88d602fa64b673d156 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 15 Dec 2016 13:02:00 -0500 Subject: [PATCH 1/2] Collection::min() incorrectly excludes 0 when calculating minimum (#16821) * Add failing test * Fix BC break in min() --- src/Illuminate/Support/Collection.php | 8 ++++++-- tests/Support/SupportCollectionTest.php | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index aaadb774c9a8..587f62b6903f 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -649,7 +649,9 @@ public function max($callback = null) { $callback = $this->valueRetriever($callback); - return $this->filter()->reduce(function ($result, $item) use ($callback) { + return $this->filter(function ($value) { + return ! is_null($value); + })->reduce(function ($result, $item) use ($callback) { $value = $callback($item); return is_null($result) || $value > $result ? $value : $result; @@ -699,7 +701,9 @@ public function min($callback = null) { $callback = $this->valueRetriever($callback); - return $this->filter()->reduce(function ($result, $item) use ($callback) { + return $this->filter(function ($value) { + return ! is_null($value); + })->reduce(function ($result, $item) use ($callback) { $value = $callback($item); return is_null($result) || $value < $result ? $value : $result; diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 92d53f0d73c5..ca84d9baf54f 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1377,6 +1377,9 @@ public function testGettingMinItemsFromCollection() $c = new Collection([1, null, 3, 4, 5]); $this->assertEquals(1, $c->min()); + $c = new Collection([0, 1, 2, 3, 4]); + $this->assertEquals(0, $c->min()); + $c = new Collection(); $this->assertNull($c->min()); } From a64fc4f8958091ca39623b2e8c8f173cb34fa47a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 15 Dec 2016 12:03:17 -0600 Subject: [PATCH 2/2] version --- src/Illuminate/Foundation/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 96ccf596d055..25c10bf14b3a 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -25,7 +25,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn * * @var string */ - const VERSION = '5.3.27'; + const VERSION = '5.3.28'; /** * The base path for the Laravel installation.