From 048ac6d49f2f7b2d64eb1695848df4590c38be98 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Feb 2021 08:42:12 -0600 Subject: [PATCH] rename method --- .../Database/Concerns/BuildsQueries.php | 40 +++++++++---------- .../Database/EloquentWhereTest.php | 4 +- .../Integration/Database/QueryBuilderTest.php | 4 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Illuminate/Database/Concerns/BuildsQueries.php b/src/Illuminate/Database/Concerns/BuildsQueries.php index c320f9d58987..34af0405e723 100644 --- a/src/Illuminate/Database/Concerns/BuildsQueries.php +++ b/src/Illuminate/Database/Concerns/BuildsQueries.php @@ -51,6 +51,26 @@ public function chunk($count, callable $callback) return true; } + /** + * Run a map over each item while chunking. + * + * @param callable $callback + * @param int $count + * @return \Illuminate\Support\Collection + */ + public function chunkMap(callable $callback, $count = 1000) + { + $collection = Collection::make(); + + $this->chunk($count, function ($items) use ($collection, $callback) { + $items->each(function ($item) use ($collection, $callback) { + $collection->push($callback($item)); + }); + }); + + return $collection; + } + /** * Execute a callback over each item while chunking. * @@ -150,26 +170,6 @@ public function first($columns = ['*']) return $this->take(1)->get($columns)->first(); } - /** - * Run a map over each item while chunking. - * - * @param callable $callback - * @param int $count - * @return \Illuminate\Support\Collection - */ - public function map(callable $callback, $count = 1000) - { - $collection = Collection::make(); - - $this->chunk($count, function ($items) use ($collection, $callback) { - $items->each(function ($item) use ($collection, $callback) { - $collection->push($callback($item)); - }); - }); - - return $collection; - } - /** * Execute the query and get the first result if it's the sole matching record. * diff --git a/tests/Integration/Database/EloquentWhereTest.php b/tests/Integration/Database/EloquentWhereTest.php index d9614e5ca5d2..7d46a8e34616 100644 --- a/tests/Integration/Database/EloquentWhereTest.php +++ b/tests/Integration/Database/EloquentWhereTest.php @@ -136,7 +136,7 @@ public function testSoleFailsIfNoRecords() $this->assertSame(UserWhereTest::class, $exception->getModel()); } - public function testMap() + public function testChunkMap() { UserWhereTest::create([ 'name' => 'first-name', @@ -152,7 +152,7 @@ public function testMap() DB::enableQueryLog(); - $results = UserWhereTest::orderBy('id')->map(function ($user) { + $results = UserWhereTest::orderBy('id')->chunkMap(function ($user) { return $user->name; }, 1); diff --git a/tests/Integration/Database/QueryBuilderTest.php b/tests/Integration/Database/QueryBuilderTest.php index b1b7e376261e..d9257dc6f309 100644 --- a/tests/Integration/Database/QueryBuilderTest.php +++ b/tests/Integration/Database/QueryBuilderTest.php @@ -214,11 +214,11 @@ public function testPaginateWithSpecificColumns() ]); } - public function testMap() + public function testChunkMap() { DB::enableQueryLog(); - $results = DB::table('posts')->orderBy('id')->map(function ($post) { + $results = DB::table('posts')->orderBy('id')->chunkMap(function ($post) { return $post->title; }, 1);