Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Builder: Remove code duplication, Add code comments #13746

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,33 +354,6 @@ public function cursor()
}
}

/**
* Chunk the results of the query.
*
* @param int $count
* @param callable $callback
* @return bool
*/
public function chunk($count, callable $callback)
{
$results = $this->forPage($page = 1, $count)->get();

while (count($results) > 0) {
// On each chunk result set, we will pass them to the callback and then let the
// developer take care of everything within the callback, which allows us to
// keep the memory low for spinning through large result sets for working.
if (call_user_func($callback, $results) === false) {
return false;
}

$page++;

$results = $this->forPage($page, $count)->get();
}

return true;
}

/**
* Chunk the results of a query by comparing numeric IDs.
*
Expand Down Expand Up @@ -749,6 +722,8 @@ protected function isNested($name, $relation)
*/
public function when($value, $callback)
{
// The callback will be passed this Eloquent Builder instance
// as a parameter, and has to return it.
$builder = $this;

if ($value) {
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ public function crossJoin($table, $first = null, $operator = null, $second = nul
*/
public function when($value, $callback)
{
// The callback will be passed this Query Builder instance
// as a parameter, and has to return it.
$builder = $this;

if ($value) {
Expand Down