Skip to content

Commit

Permalink
[5.4] Move "tap" method to BuildsQueries trait. (#20384)
Browse files Browse the repository at this point in the history
* Moved tap method to BuildsQueries trait.

* Fixed styleci.io analyse.
  • Loading branch information
ed-fruty authored and taylorotwell committed Aug 4, 2017
1 parent 4880d43 commit 4ce8d7a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Concerns/BuildsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ public function when($value, $callback, $default = null)
return $this;
}

/**
* Pass the query to a given callback.
*
* @param \Closure $callback
* @return \Illuminate\Database\Query\Builder
*/
public function tap($callback)
{
return $this->when(true, $callback);
}

/**
* Apply the callback's query changes if the given "value" is false.
*
Expand Down
11 changes: 0 additions & 11 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,6 @@ public function crossJoin($table, $first = null, $operator = null, $second = nul
return $this;
}

/**
* Pass the query to a given callback.
*
* @param \Closure $callback
* @return \Illuminate\Database\Query\Builder
*/
public function tap($callback)
{
return $this->when(true, $callback);
}

/**
* Merge an array of where clauses and bindings.
*
Expand Down
17 changes: 17 additions & 0 deletions tests/Database/DatabaseConcernsBuildsQueriesTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Illuminate\Tests\Database;

use PHPUnit\Framework\TestCase;
use Illuminate\Database\Concerns\BuildsQueries;

class DatabaseConcernsBuildsQueriesTraitTest extends TestCase
{
public function testTapCallbackInstance()
{
$mock = $this->getMockForTrait(BuildsQueries::class);
$mock->tap(function ($builder) use ($mock) {
$this->assertEquals($mock, $builder);
});
}
}

0 comments on commit 4ce8d7a

Please sign in to comment.