Skip to content

Commit 0ffc6bf

Browse files
committed
Add conditional return type to Builder::raw()
for both the Eloquent and the Query builder, so that developers can understand that the return type will either be a `Collection` or an `Expression` based on the argument that's passed to `raw()`
1 parent ea742b8 commit 0ffc6bf

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Eloquent/Builder.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace MongoDB\Laravel\Eloquent;
66

7+
use Closure;
78
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
89
use Illuminate\Database\Eloquent\Collection;
910
use Illuminate\Database\Eloquent\Model;
1011
use MongoDB\BSON\Document;
12+
use MongoDB\Builder\Expression;
1113
use MongoDB\Builder\Type\QueryInterface;
1214
use MongoDB\Builder\Type\SearchOperatorInterface;
1315
use MongoDB\Driver\CursorInterface;
@@ -229,7 +231,13 @@ public function decrement($column, $amount = 1, array $extra = [])
229231
return parent::decrement($column, $amount, $extra);
230232
}
231233

232-
/** @inheritdoc */
234+
/**
235+
* @param (Closure():T)|Expression|null $value
236+
*
237+
* @return ($value is Closure ? T : ($value is null ? Collection : Expression))
238+
*
239+
* @template T
240+
*/
233241
public function raw($value = null)
234242
{
235243
// Get raw results from the query builder.

src/Query/Builder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,13 @@ public function lists($column, $key = null)
964964
return $this->pluck($column, $key);
965965
}
966966

967-
/** @inheritdoc */
967+
/**
968+
* @param (Closure():T)|Expression|null $value
969+
*
970+
* @return ($value is Closure ? T : ($value is null ? Collection : Expression))
971+
*
972+
* @template T
973+
*/
968974
public function raw($value = null)
969975
{
970976
// Execute the closure on the mongodb collection

0 commit comments

Comments
 (0)