28
28
use Override ;
29
29
use RuntimeException ;
30
30
use stdClass ;
31
+ use TypeError ;
31
32
32
33
use function array_fill_keys ;
33
34
use function array_is_list ;
@@ -335,7 +336,7 @@ public function toMql(): array
335
336
if ($ this ->aggregate ) {
336
337
$ function = $ this ->aggregate ['function ' ];
337
338
338
- foreach (( array ) $ this ->aggregate ['columns ' ] as $ column ) {
339
+ foreach ($ this ->aggregate ['columns ' ] as $ column ) {
339
340
// Add unwind if a subdocument array should be aggregated
340
341
// column: subarray.price => {$unwind: '$subarray'}
341
342
$ splitColumns = explode ('.*. ' , $ column );
@@ -344,7 +345,7 @@ public function toMql(): array
344
345
$ column = implode ('. ' , $ splitColumns );
345
346
}
346
347
347
- $ aggregations = blank ($ this ->aggregate ['columns ' ]) ? [] : ( array ) $ this ->aggregate ['columns ' ];
348
+ $ aggregations = blank ($ this ->aggregate ['columns ' ]) ? [] : $ this ->aggregate ['columns ' ];
348
349
349
350
if (in_array ('* ' , $ aggregations ) && $ function === 'count ' && empty ($ group ['_id ' ])) {
350
351
$ options = $ this ->inheritConnectionOptions ($ this ->options );
@@ -484,11 +485,11 @@ public function getFresh($columns = [], $returnLazy = false)
484
485
// here to either the passed columns, or the standard default of retrieving
485
486
// all of the columns on the table using the "wildcard" column character.
486
487
if ($ this ->columns === null ) {
487
- $ this ->columns = ( array ) $ columns ;
488
+ $ this ->columns = $ columns ;
488
489
}
489
490
490
491
// Drop all columns if * is present, MongoDB does not work this way.
491
- if (in_array ('* ' , ( array ) $ this ->columns )) {
492
+ if (in_array ('* ' , $ this ->columns )) {
492
493
$ this ->columns = [];
493
494
}
494
495
@@ -556,6 +557,8 @@ public function generateCacheKey()
556
557
/** @return ($function is null ? AggregationBuilder : mixed) */
557
558
public function aggregate ($ function = null , $ columns = ['* ' ])
558
559
{
560
+ assert (is_array ($ columns ), new TypeError (sprintf ('Argument #2 ($columns) must be of type array, %s given ' , get_debug_type ($ columns ))));
561
+
559
562
if ($ function === null ) {
560
563
if (! trait_exists (FluentFactoryTrait::class)) {
561
564
// This error will be unreachable when the mongodb/builder package will be merged into mongodb/mongodb
0 commit comments