Skip to content

Commit 6c7df45

Browse files
authored
Remove Query\Builder::__constructor overload (#2570)
1 parent b484288 commit 6c7df45

File tree

6 files changed

+16
-21
lines changed

6 files changed

+16
-21
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
1616
- Remove `Query\Builder::whereAll($column, $values)`. Use `Query\Builder::where($column, 'all', $values)` instead. [#16](https://github.com/GromNaN/laravel-mongodb/pull/16) by [@GromNaN](https://github.com/GromNaN).
1717
- Fix validation of unique values when the validated value is found as part of an existing value. [#21](https://github.com/GromNaN/laravel-mongodb/pull/21) by [@GromNaN](https://github.com/GromNaN).
1818
- Support `%` and `_` in `like` expression [#17](https://github.com/GromNaN/laravel-mongodb/pull/17) by [@GromNaN](https://github.com/GromNaN).
19+
- Change signature of `Query\Builder::__constructor` to match the parent class [#26](https://github.com/GromNaN/laravel-mongodb-private/pull/26) by [@GromNaN](https://github.com/GromNaN).
1920

2021
## [3.9.2] - 2022-09-01
2122

Diff for: src/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(array $config)
7373
*/
7474
public function collection($collection)
7575
{
76-
$query = new Query\Builder($this, $this->getPostProcessor());
76+
$query = new Query\Builder($this, $this->getQueryGrammar(), $this->getPostProcessor());
7777

7878
return $query->from($collection);
7979
}

Diff for: src/Eloquent/Builder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ public function decrement($column, $amount = 1, array $extra = [])
156156
/**
157157
* @inheritdoc
158158
*/
159-
public function raw($expression = null)
159+
public function raw($value = null)
160160
{
161161
// Get raw results from the query builder.
162-
$results = $this->query->raw($expression);
162+
$results = $this->query->raw($value);
163163

164164
// Convert MongoCursor results to a collection of models.
165165
if ($results instanceof Cursor) {

Diff for: src/Eloquent/Model.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ protected function newBaseQueryBuilder()
433433
{
434434
$connection = $this->getConnection();
435435

436-
return new QueryBuilder($connection, $connection->getPostProcessor());
436+
return new QueryBuilder($connection, $connection->getQueryGrammar(), $connection->getPostProcessor());
437437
}
438438

439439
/**

Diff for: src/Query/Builder.php

+8-16
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,6 @@ class Builder extends BaseBuilder
133133
'uniquedocs' => 'uniqueDocs',
134134
];
135135

136-
/**
137-
* @inheritdoc
138-
*/
139-
public function __construct(Connection $connection, Processor $processor)
140-
{
141-
$this->grammar = new Grammar;
142-
$this->connection = $connection;
143-
$this->processor = $processor;
144-
}
145-
146136
/**
147137
* Set the projections.
148138
*
@@ -757,16 +747,16 @@ public function lists($column, $key = null)
757747
/**
758748
* @inheritdoc
759749
*/
760-
public function raw($expression = null)
750+
public function raw($value = null)
761751
{
762752
// Execute the closure on the mongodb collection
763-
if ($expression instanceof Closure) {
764-
return call_user_func($expression, $this->collection);
753+
if ($value instanceof Closure) {
754+
return call_user_func($value, $this->collection);
765755
}
766756

767757
// Create an expression for the given value
768-
if ($expression !== null) {
769-
return new Expression($expression);
758+
if ($value !== null) {
759+
return new Expression($value);
770760
}
771761

772762
// Quick access to the mongodb collection
@@ -852,10 +842,12 @@ public function drop($columns)
852842

853843
/**
854844
* @inheritdoc
845+
*
846+
* @return static
855847
*/
856848
public function newQuery()
857849
{
858-
return new self($this->connection, $this->processor);
850+
return new static($this->connection, $this->grammar, $this->processor);
859851
}
860852

861853
/**

Diff for: tests/Query/BuilderTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Tests\Database\DatabaseQueryBuilderTest;
1010
use Jenssegers\Mongodb\Connection;
1111
use Jenssegers\Mongodb\Query\Builder;
12+
use Jenssegers\Mongodb\Query\Grammar;
1213
use Jenssegers\Mongodb\Query\Processor;
1314
use Mockery as m;
1415
use MongoDB\BSON\Regex;
@@ -838,7 +839,8 @@ private static function getBuilder(): Builder
838839
$connection = m::mock(Connection::class);
839840
$processor = m::mock(Processor::class);
840841
$connection->shouldReceive('getSession')->andReturn(null);
842+
$connection->shouldReceive('getQueryGrammar')->andReturn(new Grammar());
841843

842-
return new Builder($connection, $processor);
844+
return new Builder($connection, null, $processor);
843845
}
844846
}

0 commit comments

Comments
 (0)