From f454be7e4df31a4969eb0f0ec8f9614b410e23b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Sim=C3=A3o?= Date: Mon, 9 Jan 2023 14:26:41 -0300 Subject: [PATCH 1/3] Rename Query::addSort() --- docs/how-to/query-database.md | 2 +- src/Databases/Query.php | 4 ++-- tests/Unit/Databases/QueryTest.php | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/how-to/query-database.md b/docs/how-to/query-database.md index dd180149..02e7474c 100644 --- a/docs/how-to/query-database.md +++ b/docs/how-to/query-database.md @@ -23,7 +23,7 @@ $query = Query::create() TextFilter::property("Name")->contains("John"), ) ) - ->withAddedSort(Sort::property("Name")->ascending()) + ->addSort(Sort::property("Name")->ascending()) ->withPageSize(20); $result = $notion->databases()->query($database, $query); diff --git a/src/Databases/Query.php b/src/Databases/Query.php index b3e3d4f4..7c8e954e 100644 --- a/src/Databases/Query.php +++ b/src/Databases/Query.php @@ -30,8 +30,8 @@ public function changeFilter(Filter $filter): self return new self($filter, $this->sorts, $this->startCursor, $this->pageSize); } - /** Add new sort change lowest priority */ - public function changeAddedSort(Sort $sort): self + /** Add new sort with lowest priority */ + public function addSort(Sort $sort): self { $sorts = $this->sorts; $sorts[] = $sort; diff --git a/tests/Unit/Databases/QueryTest.php b/tests/Unit/Databases/QueryTest.php index ec72749b..e3c8e969 100644 --- a/tests/Unit/Databases/QueryTest.php +++ b/tests/Unit/Databases/QueryTest.php @@ -31,8 +31,8 @@ public function test_query_change_filter(): void public function test_add_sort(): void { $query = Query::create() - ->changeAddedSort(Sort::createdTime()->descending()) - ->changeAddedSort(Sort::property("Title")->ascending()); + ->addSort(Sort::createdTime()->descending()) + ->addSort(Sort::property("Title")->ascending()); $this->assertCount(2, $query->sorts); } @@ -40,8 +40,8 @@ public function test_add_sort(): void public function test_replace_sorts(): void { $query = Query::create() - ->changeAddedSort(Sort::createdTime()->descending()) - ->changeAddedSort(Sort::property("Title")->ascending()) + ->addSort(Sort::createdTime()->descending()) + ->addSort(Sort::property("Title")->ascending()) ->changeSorts(Sort::lastEditedTime()->descending()); $this->assertCount(1, $query->sorts); @@ -87,7 +87,7 @@ public function test_complete_query_to_array(): void { $query = Query::create() ->changeFilter(TextFilter::property("Title")->contains("abc")) - ->changeAddedSort(Sort::property("Title")->ascending()) + ->addSort(Sort::property("Title")->ascending()) ->changeStartCursor("889431ed-4f50-460b-a926-36f6cf0f9669") ->changePageSize(20); From 646c4f9a4530b5efad2eb9854f1e6e6c1877a55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Sim=C3=A3o?= Date: Mon, 9 Jan 2023 14:31:00 -0300 Subject: [PATCH 2/3] Rename Query::addSort() 2 --- src/Databases/Query.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Databases/Query.php b/src/Databases/Query.php index 7c8e954e..2bafab2b 100644 --- a/src/Databases/Query.php +++ b/src/Databases/Query.php @@ -39,6 +39,15 @@ public function addSort(Sort $sort): self return new self($this->filter, $sorts, $this->startCursor, $this->pageSize); } + /** + * @deprecated 1.1.0 This method will be removed in future versions. Use 'addSort' instead. + * @see \Notion\Databases\Query::addSort() + */ + public function changeAddedSort(Sort $sort): self + { + return $this->addSort($sort); + } + /** Replace all sorts */ public function changeSorts(Sort ...$sorts): self { From 75ad402666e656e42b51568a5d8511e7e37f2351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Sim=C3=A3o?= Date: Mon, 9 Jan 2023 14:41:19 -0300 Subject: [PATCH 3/3] Rename Query::addSort() 3 --- tests/Unit/Databases/QueryTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Unit/Databases/QueryTest.php b/tests/Unit/Databases/QueryTest.php index e3c8e969..35426f9e 100644 --- a/tests/Unit/Databases/QueryTest.php +++ b/tests/Unit/Databases/QueryTest.php @@ -47,6 +47,16 @@ public function test_replace_sorts(): void $this->assertCount(1, $query->sorts); } + /** @psalm-suppress DeprecatedMethod */ + public function test_deprecated_change_added_sort(): void + { + $query = Query::create() + ->changeAddedSort(Sort::createdTime()->descending()) + ->changeAddedSort(Sort::property("Title")->ascending()); + + $this->assertCount(2, $query->sorts); + } + public function test_query_change_start_cursor(): void { $query = Query::create()