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 @@ -4,6 +4,7 @@

- New #150: Extract `withLimit()` from `ReadableDataInterface` into `LimitableDataInterface` (@vjik)
- Enh #150: `PaginatorInterface` now extends `ReadableDataInterface` (@vjik)
- Chg #151: Rename `isRequired()` method in `PaginatorInterface` to `isPaginationRequired()` (@vjik)

## 1.0.1 January 25, 2023

Expand Down
2 changes: 1 addition & 1 deletion src/Paginator/KeysetPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function isOnLastPage(): bool
return !$this->hasNextPage;
}

public function isRequired(): bool
public function isPaginationRequired(): bool
{
return !$this->isOnFirstPage() || !$this->isOnLastPage();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Paginator/OffsetPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function isOnLastPage(): bool
return $this->currentPage === $this->getInternalTotalPages();
}

public function isRequired(): bool
public function isPaginationRequired(): bool
{
return $this->getTotalPages() > 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Paginator/PaginatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ public function isOnFirstPage(): bool;
*
* @return bool Whether pagination is required.
*/
public function isRequired(): bool;
public function isPaginationRequired(): bool;
}
10 changes: 5 additions & 5 deletions tests/Paginator/KeysetPaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public function testIsOnFirstPage(): void
$paginator = (new KeysetPaginator($dataReader))->withPageSize(2);

$this->assertTrue($paginator->isOnFirstPage());
$this->assertTrue($paginator->isRequired());
$this->assertTrue($paginator->isPaginationRequired());
}

public function testIsOnLastPage(): void
Expand All @@ -416,20 +416,20 @@ public function testIsOnLastPage(): void

$paginator = $paginator->withNextPageToken('2');
$this->assertFalse($paginator->isOnLastPage());
$this->assertTrue($paginator->isRequired());
$this->assertTrue($paginator->isPaginationRequired());
}

public function testIsRequired(): void
public function testIsPaginationRequired(): void
{
$sort = Sort::only(['id'])->withOrderString('id');
$dataReader = (new IterableDataReader($this->getDataSet()))->withSort($sort);
$paginator = new KeysetPaginator($dataReader);

$this->assertFalse($paginator->isRequired());
$this->assertFalse($paginator->isPaginationRequired());

$paginator = $paginator->withPageSize(2);

$this->assertTrue($paginator->isRequired());
$this->assertTrue($paginator->isPaginationRequired());
}

public function testCurrentPageSize(): void
Expand Down
8 changes: 4 additions & 4 deletions tests/Paginator/OffsetPaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ public function testDefaultState(): void
$this->assertSame(0, $paginator->getOffset());
$this->assertSame(1, $paginator->getCurrentPage());
$this->assertTrue($paginator->isOnFirstPage());
$this->assertFalse($paginator->isRequired());
$this->assertFalse($paginator->isPaginationRequired());
}

public function testIsRequired(): void
public function testIsPaginationRequired(): void
{
$dataReader = new IterableDataReader(self::DEFAULT_DATASET);
$paginator = (new OffsetPaginator($dataReader))->withPageSize(2);

$this->assertTrue($paginator->isRequired());
$this->assertTrue($paginator->isPaginationRequired());
}

public function testGetTotalItems(): void
Expand Down Expand Up @@ -463,7 +463,7 @@ public function testEmptyDataSet(): void
$this->assertSame(1, $paginator->getCurrentPage());
$this->assertTrue($paginator->isOnFirstPage());
$this->assertTrue($paginator->isOnLastPage());
$this->assertFalse($paginator->isRequired());
$this->assertFalse($paginator->isPaginationRequired());
$this->assertSame([], $this->iterableToArray($paginator->read()));
}

Expand Down