Skip to content

Use default order from Sort in KeysetPaginator#223

Merged
vjik merged 3 commits intomasterfrom
212-sort
Jun 13, 2025
Merged

Use default order from Sort in KeysetPaginator#223
vjik merged 3 commits intomasterfrom
212-sort

Conversation

@vjik
Copy link
Member

@vjik vjik commented Jun 11, 2025

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fix #212

@vjik vjik added the status:code review The pull request needs review. label Jun 11, 2025
@vjik vjik requested a review from a team June 11, 2025 14:47
@samdark samdark requested review from Copilot June 12, 2025 21:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for using default sort orders in KeysetPaginator when no explicit order is provided, including backwards pagination support, and updates related tests and documentation.

  • Introduces Sort::getDefaultOrder() to retrieve default sorting fields.
  • Modifies KeysetPaginator to apply a single default sort key when the provided sort is empty.
  • Updates tests to validate default ordering behavior; bumps rector/rector dev dependency and updates CHANGELOG.md.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Paginator/KeysetPaginatorTest.php Replaces “not sorted” exception test with default-order tests; adjusts exception test to use empty sort
src/Reader/Sort.php Adds getDefaultOrder() method to expose configured defaults
src/Paginator/KeysetPaginator.php Refactors constructor and withSort() to use default sort via prepareSortInDataReader(); removes old assertSort()
composer.json Bumps rector/rector from 2.0.15 to 2.0.18
CHANGELOG.md Logs addition of getDefaultOrder() and enhanced default-order behavior in KeysetPaginator
Comments suppressed due to low confidence (1)

src/Paginator/KeysetPaginator.php:439

  • The docblock above declares a more specific return type (FilterableDataInterface&LimitableDataInterface&ReadableDataInterface&SortableDataInterface) than the declared return type ReadableDataInterface. Please align the signature and docblock so they match the intended interfaces returned by withSort().
private function prepareSortInDataReader(ReadableDataInterface $dataReader, ?Sort $sort): ReadableDataInterface

$this->expectExceptionMessage('Data should be always sorted to work with keyset pagination.');

(new KeysetPaginator($dataReader))->withSort(Sort::only(['id', 'name']));
(new KeysetPaginator($dataReader))->withSort(Sort::only([]));
Copy link

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test expects an exception when using an empty sort, but KeysetPaginator now applies the default order and won’t throw. Consider disabling default sorting on the Sort instance (e.g., via a dedicated API) or updating the test to reflect that an empty sort yields default ordering rather than an error.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vjik vjik merged commit a737b94 into master Jun 13, 2025
20 of 21 checks passed
@vjik vjik deleted the 212-sort branch June 13, 2025 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set default $currentOrder in Sort class

5 participants