Skip to content

Commit

Permalink
Minor Builder cleanup (#13884)
Browse files Browse the repository at this point in the history
  • Loading branch information
acasar authored and taylorotwell committed Jun 5, 2016
1 parent 99a35d7 commit 2341879
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ public function orWhereHas($relation, Closure $callback, $operator = '>=', $coun
* @param string $operator
* @param int $count
* @param string $boolean
* @return \Illuminate\Database\Eloquent\Builder
* @return \Illuminate\Database\Eloquent\Builder|static
*/
protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, $count, $boolean)
{
Expand Down Expand Up @@ -983,7 +983,7 @@ protected function whereCountQuery(QueryBuilder $query, $operator = '>=', $count
* Merge the constraints from a relation query to the current query.
*
* @param \Illuminate\Database\Eloquent\Builder $relation
* @return void
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function mergeModelDefinedRelationConstraints(Builder $relation)
{
Expand Down Expand Up @@ -1194,10 +1194,10 @@ protected function shouldNestWheresForScope(QueryBuilder $query, $originalWhereC
* Nest where conditions by slicing them at the given where count.
*
* @param \Illuminate\Database\Query\Builder $query
* @param int|array $whereCounts
* @param int $originalWhereCount
* @return void
*/
protected function nestWheresForScope(QueryBuilder $query, $whereCounts)
protected function nestWheresForScope(QueryBuilder $query, $originalWhereCount)
{
// Here, we totally remove all of the where clauses since we are going to
// rebuild them as nested queries by slicing the groups of wheres into
Expand All @@ -1206,34 +1206,22 @@ protected function nestWheresForScope(QueryBuilder $query, $whereCounts)

$query->wheres = [];

// We will construct where offsets by adding the outer most offsets to the
// collection (0 and total where count) while also flattening the array
// and extracting unique values, ensuring that all wheres are sliced.
$whereOffsets = collect([0, $whereCounts, count($allWheres)])->flatten()->unique();

$sliceFrom = $whereOffsets->shift();

foreach ($whereOffsets as $sliceTo) {
$this->sliceWhereConditions(
$query, $allWheres, $sliceFrom, $sliceTo
);

$sliceFrom = $sliceTo;
}
$this->sliceWhereConditions($query, $allWheres, 0, $originalWhereCount);
$this->sliceWhereConditions($query, $allWheres, $originalWhereCount);
}

/**
* Create a slice of where conditions at the given offsets and nest them if needed.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $wheres
* @param int $sliceFrom
* @param int $sliceTo
* @param int $offset
* @param int $length
* @return void
*/
protected function sliceWhereConditions(QueryBuilder $query, array $wheres, $sliceFrom, $sliceTo)
protected function sliceWhereConditions(QueryBuilder $query, $wheres, $offset, $length = null)
{
$whereSlice = array_slice($wheres, $sliceFrom, $sliceTo - $sliceFrom);
$whereSlice = array_slice($wheres, $offset, $length);

$whereBooleans = collect($whereSlice)->pluck('boolean');

Expand Down

0 comments on commit 2341879

Please sign in to comment.