2828use Override ;
2929use RuntimeException ;
3030use stdClass ;
31+ use TypeError ;
3132
3233use function array_fill_keys ;
3334use function array_is_list ;
@@ -335,7 +336,7 @@ public function toMql(): array
335336 if ($ this ->aggregate ) {
336337 $ function = $ this ->aggregate ['function ' ];
337338
338- foreach (( array ) $ this ->aggregate ['columns ' ] as $ column ) {
339+ foreach ($ this ->aggregate ['columns ' ] as $ column ) {
339340 // Add unwind if a subdocument array should be aggregated
340341 // column: subarray.price => {$unwind: '$subarray'}
341342 $ splitColumns = explode ('.*. ' , $ column );
@@ -344,7 +345,7 @@ public function toMql(): array
344345 $ column = implode ('. ' , $ splitColumns );
345346 }
346347
347- $ aggregations = blank ($ this ->aggregate ['columns ' ]) ? [] : ( array ) $ this ->aggregate ['columns ' ];
348+ $ aggregations = blank ($ this ->aggregate ['columns ' ]) ? [] : $ this ->aggregate ['columns ' ];
348349
349350 if (in_array ('* ' , $ aggregations ) && $ function === 'count ' && empty ($ group ['_id ' ])) {
350351 $ options = $ this ->inheritConnectionOptions ($ this ->options );
@@ -484,11 +485,11 @@ public function getFresh($columns = [], $returnLazy = false)
484485 // here to either the passed columns, or the standard default of retrieving
485486 // all of the columns on the table using the "wildcard" column character.
486487 if ($ this ->columns === null ) {
487- $ this ->columns = ( array ) $ columns ;
488+ $ this ->columns = $ columns ;
488489 }
489490
490491 // 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 )) {
492493 $ this ->columns = [];
493494 }
494495
@@ -556,6 +557,8 @@ public function generateCacheKey()
556557 /** @return ($function is null ? AggregationBuilder : mixed) */
557558 public function aggregate ($ function = null , $ columns = ['* ' ])
558559 {
560+ assert (is_array ($ columns ), new TypeError (sprintf ('Argument #2 ($columns) must be of type array, %s given ' , get_debug_type ($ columns ))));
561+
559562 if ($ function === null ) {
560563 if (! trait_exists (FluentFactoryTrait::class)) {
561564 // This error will be unreachable when the mongodb/builder package will be merged into mongodb/mongodb
0 commit comments