Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +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 checks for the presence of a field in the sort config (@vjik)

## 1.0.1 January 25, 2023

Expand Down
10 changes: 10 additions & 0 deletions src/Reader/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
9 changes: 9 additions & 0 deletions tests/Reader/SortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}