Skip to content

Commit 4ce8d7a

Browse files
ed-frutytaylorotwell
authored andcommitted
[5.4] Move "tap" method to BuildsQueries trait. (#20384)
* Moved tap method to BuildsQueries trait. * Fixed styleci.io analyse.
1 parent 4880d43 commit 4ce8d7a

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/Illuminate/Database/Concerns/BuildsQueries.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ public function when($value, $callback, $default = null)
9494
return $this;
9595
}
9696

97+
/**
98+
* Pass the query to a given callback.
99+
*
100+
* @param \Closure $callback
101+
* @return \Illuminate\Database\Query\Builder
102+
*/
103+
public function tap($callback)
104+
{
105+
return $this->when(true, $callback);
106+
}
107+
97108
/**
98109
* Apply the callback's query changes if the given "value" is false.
99110
*

src/Illuminate/Database/Query/Builder.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,6 @@ public function crossJoin($table, $first = null, $operator = null, $second = nul
459459
return $this;
460460
}
461461

462-
/**
463-
* Pass the query to a given callback.
464-
*
465-
* @param \Closure $callback
466-
* @return \Illuminate\Database\Query\Builder
467-
*/
468-
public function tap($callback)
469-
{
470-
return $this->when(true, $callback);
471-
}
472-
473462
/**
474463
* Merge an array of where clauses and bindings.
475464
*
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Database;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Illuminate\Database\Concerns\BuildsQueries;
7+
8+
class DatabaseConcernsBuildsQueriesTraitTest extends TestCase
9+
{
10+
public function testTapCallbackInstance()
11+
{
12+
$mock = $this->getMockForTrait(BuildsQueries::class);
13+
$mock->tap(function ($builder) use ($mock) {
14+
$this->assertEquals($mock, $builder);
15+
});
16+
}
17+
}

0 commit comments

Comments
 (0)