From 9f03dda2ff5a7d676553f1ce3f891cd13b3ecca2 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 25 Jan 2024 11:45:27 +0300 Subject: [PATCH 1/2] Add `Sort::hasFieldInConfig()` --- CHANGELOG.md | 1 + src/Reader/Sort.php | 10 ++++++++++ tests/Reader/SortTest.php | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba01879..78958ffc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Bug #155: Fix `Sort` configuration preparation (@vjik) - Bug #155: Fix same named order fields in `Sort` were not overriding previous ones (@vjik) - New #158: Add methods `PaginatorInterface::isSortable()` and `PaginatorInterface::withSort()` (@vjik) +- New #158: Add `Sort::hasFieldInConfig()` method that check for the presence of a field in the sort config (@vjik) ## 1.0.1 January 25, 2023 diff --git a/src/Reader/Sort.php b/src/Reader/Sort.php index d71d79bf..ca5ed950 100644 --- a/src/Reader/Sort.php +++ b/src/Reader/Sort.php @@ -330,4 +330,14 @@ public function getCriteria(): array return $criteria; } + + /** + * @param string $name The field name. + * + * @return bool Whether the field is present in the config. + */ + public function hasFieldInConfig(string $name): bool + { + return isset($this->config[$name]); + } } diff --git a/tests/Reader/SortTest.php b/tests/Reader/SortTest.php index d680f6b7..8c9dcd2b 100644 --- a/tests/Reader/SortTest.php +++ b/tests/Reader/SortTest.php @@ -333,4 +333,13 @@ public function testPrepareConfig(array $expected, array $config): void $sort = Sort::only($config); $this->assertSame($expected, $sort->getCriteria()); } + + public function testHasFieldInConfig(): void + { + $sort = Sort::only(['a', 'b']); + + $this->assertTrue($sort->hasFieldInConfig('a')); + $this->assertTrue($sort->hasFieldInConfig('b')); + $this->assertFalse($sort->hasFieldInConfig('c')); + } } From 3076273e8b4ba8cbccce4cc8db0d592ad5367827 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 26 Jan 2024 10:53:03 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a539489..8d5039d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - Chg #159: Replace `withNextPageToken()` and `withPreviousPageToken()` of `PaginatorInterface` with `withToken()`, `getNextPageToken()` with `getNextToken()`, `getPreviousPageToken()` with `getPreviousToken()`, and add `getToken()`. These methods use new `PageToken` class (@vjik) -- New #160: Add `Sort::hasFieldInConfig()` method that check for the presence of a field in the sort config (@vjik) +- New #160: Add `Sort::hasFieldInConfig()` method that checks for the presence of a field in the sort config (@vjik) ## 1.0.1 January 25, 2023