Skip to content

Commit

Permalink
Rename isRequired() method in PaginatorInterface to `isPagination…
Browse files Browse the repository at this point in the history
…Required()` (#151)
  • Loading branch information
vjik committed Jan 8, 2024
1 parent e2fd7e0 commit 408742d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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
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
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
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
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

0 comments on commit 408742d

Please sign in to comment.