File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed
Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -93,16 +93,20 @@ public function toArray(): array
9393 }
9494
9595 /**
96- * @param Collection $sortings
96+ * @param Sorting| Collection $sortings
9797 * @return array
9898 */
99- public static function sortQuery (Collection $ sortings ): array
99+ public static function sortQuery (Sorting | Collection $ sortings ): array
100100 {
101101 $ querySortings = new Collection ();
102102
103- $ sortings ->each (function (Sorting $ sorting ) use ($ querySortings ) {
104- $ querySortings ->add ($ sorting ->toArray ());
105- });
103+ if ($ sortings instanceof Collection) {
104+ $ sortings ->each (function (Sorting $ sorting ) use ($ querySortings ) {
105+ $ querySortings ->push ($ sorting ->toArray ());
106+ });
107+ } else {
108+ $ querySortings ->push ($ sortings ->toArray ());
109+ }
106110
107111 return $ querySortings ->toArray ();
108112 }
Original file line number Diff line number Diff line change 55use Illuminate \Support \Collection ;
66
77it ('can sort by a single property ' , function () {
8- $ expectedSortQuery = '[{"property":"Birth year","direction":"ascending"} ' ;
8+ $ expectedSortQuery = '[{"property":"Birth year","direction":"ascending"}] ' ;
99
1010 $ sortBy = Sorting::propertySort ("Birth year " , "ascending " );
1111 $ this ->assertEquals ($ expectedSortQuery , json_encode (Sorting::sortQuery ($ sortBy )));});
2222});
2323
2424it ('refuses other classes than sorting or collection in the sortBy() method ' , function () {
25- $ this ->expectException (HandlingException ::class);
25+ $ this ->expectException (TypeError ::class);
2626
2727 Notion::database ('8284f3ff77e24d4a939d19459e4d6bdc ' )
2828 ->sortBy (new stdClass ())
You can’t perform that action at this time.
0 commit comments