Skip to content

Commit

Permalink
Preparing 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsizemore committed Mar 2, 2024
1 parent 44018e1 commit e279c84
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 98 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ you can use the following url: https://github.com/ericsizemore/pagination/compar

Simply replace the version numbers depending on which set of changes you wish to see.

### 2.0.1 (2024-03-02)

Mostly small coding standard (CS) related changes, with some improvements to method docblocks throughout.

#### Changed

* Bumped version to `2.0.1`.
* Small change to how `$pagesInRange` within `paginate()` is determined.
* (CS) Rearranged the order of methods within `Paginator` and `PaginatorInterface`.
* Made the following helper functions static:
* `determinePageRange()`
* `determinePreviousPageNumber()`
* `determineNextPageNumber()`
* Updated `composer.lock`

#### Added

* Added validation to `Paginator`'s construct for the passed `$config` parameter.
* Uses a new helper function `validateConfig()`, which is a static protected method.
* Added some documentation/docblocks throughout, mostly to the `PaginatorInterface`.
* Added `ext-pdo` and `ext-pdo_sqlite` to the composer require-dev.
* Added the `Override` attribute to `Paginator` methods that are from `PaginatorInterface`.

#### Removed

* None


### 2.0.0 (2024-02-28)

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"php": "^8.2 <8.5"
},
"require-dev": {
"ext-pdo": "*",
"ext-pdo_sqlite": "*",
"friendsofphp/php-cs-fixer": "dev-master",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-phpunit": "^1.4",
Expand Down Expand Up @@ -66,4 +68,4 @@
"phpstan": "vendor/bin/phpstan analyse -c phpstan.neon",
"test": "phpunit"
}
}
}
31 changes: 17 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Exception/CallbackInvalidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Pagination - Simple, lightweight and universal service that implements pagination on collections of things.
*
* @author Eric Sizemore <admin@secondversion.com>
* @version 2.0.0
* @version 2.0.1
* @copyright (C) 2024 Eric Sizemore
* @license The MIT License (MIT)
*
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/CallbackNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Pagination - Simple, lightweight and universal service that implements pagination on collections of things.
*
* @author Eric Sizemore <admin@secondversion.com>
* @version 2.0.0
* @version 2.0.1
* @copyright (C) 2024 Eric Sizemore
* @license The MIT License (MIT)
*
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidPageNumberException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Pagination - Simple, lightweight and universal service that implements pagination on collections of things.
*
* @author Eric Sizemore <admin@secondversion.com>
* @version 2.0.0
* @version 2.0.1
* @copyright (C) 2024 Eric Sizemore
* @license The MIT License (MIT)
*
Expand Down
57 changes: 55 additions & 2 deletions src/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Pagination - Simple, lightweight and universal service that implements pagination on collections of things.
*
* @author Eric Sizemore <admin@secondversion.com>
* @version 2.0.0
* @version 2.0.1
* @copyright (C) 2024 Eric Sizemore
* @license The MIT License (MIT)
*
Expand Down Expand Up @@ -48,48 +48,86 @@
use function count;

/**
* Class Pagination
* Pagination class.
*
* @implements IteratorAggregate<(int|string), int>
*/
class Pagination implements IteratorAggregate, Countable
{
/**
* Item collection.
*
* @var array<int>
*/
private array $items = [];

/**
* Page collection.
*
* @var array<int>
*/
private array $pages = [];

/**
* Total number of pages for the item collection.
*/
private int $totalNumberOfPages;

/**
* Current page number of item collection.
*/
private int $currentPageNumber;

/**
* First page number of item collection.
*/
private int $firstPageNumber;

/**
* Last page number of item collection.
*/
private int $lastPageNumber;

/**
* Previous page number. Will be null if on the first page.
*/
private ?int $previousPageNumber = null;

/**
* Next page number. Will be null if on the last page.
*/
private ?int $nextPageNumber = null;

/**
* Currently set amount of items we want per page.
*/
private int $itemsPerPage;

/**
* Total number of items in the collection.
*/
private int $totalNumberOfItems;

/**
* Given a page range, first page number.
*/
private int $firstPageNumberInRange;

/**
* Given a page range, last page number.
*/
private int $lastPageNumberInRange;

/**
* Optional meta data to include with pagination.
*
* @var array<int|string, string>|array<mixed>
*/
private array $meta;

/**
* Returns the current collection.
*
* @return array<int>
*/
public function getItems(): array
Expand All @@ -98,11 +136,14 @@ public function getItems(): array
}

/**
* Sets the item collection to be paginated.
*
* @param array<int> $items
*/
public function setItems(array $items): static
{
$this->items = $items;

return $this;
}

Expand All @@ -114,6 +155,7 @@ public function getCurrentPageNumber(): int
public function setCurrentPageNumber(int $currentPageNumber): static
{
$this->currentPageNumber = $currentPageNumber;

return $this;
}

Expand All @@ -125,6 +167,7 @@ public function getFirstPageNumber(): int
public function setFirstPageNumber(int $firstPageNumber): static
{
$this->firstPageNumber = $firstPageNumber;

return $this;
}

Expand All @@ -136,6 +179,7 @@ public function getFirstPageNumberInRange(): int
public function setFirstPageNumberInRange(int $firstPageNumberInRange): static
{
$this->firstPageNumberInRange = $firstPageNumberInRange;

return $this;
}

Expand All @@ -147,6 +191,7 @@ public function getItemsPerPage(): int
public function setItemsPerPage(int $itemsPerPage): static
{
$this->itemsPerPage = $itemsPerPage;

return $this;
}

Expand All @@ -158,6 +203,7 @@ public function getLastPageNumber(): int
public function setLastPageNumber(int $lastPageNumber): static
{
$this->lastPageNumber = $lastPageNumber;

return $this;
}

Expand All @@ -169,6 +215,7 @@ public function getLastPageNumberInRange(): int
public function setLastPageNumberInRange(int $lastPageNumberInRange): static
{
$this->lastPageNumberInRange = $lastPageNumberInRange;

return $this;
}

Expand All @@ -180,6 +227,7 @@ public function getNextPageNumber(): ?int
public function setNextPageNumber(?int $nextPageNumber): static
{
$this->nextPageNumber = $nextPageNumber;

return $this;
}

Expand All @@ -197,6 +245,7 @@ public function getPages(): array
public function setPages(array $pages): static
{
$this->pages = $pages;

return $this;
}

Expand All @@ -208,6 +257,7 @@ public function getPreviousPageNumber(): ?int
public function setPreviousPageNumber(?int $previousPageNumber): static
{
$this->previousPageNumber = $previousPageNumber;

return $this;
}

Expand All @@ -219,6 +269,7 @@ public function getTotalNumberOfItems(): int
public function setTotalNumberOfItems(int $totalNumberOfItems): static
{
$this->totalNumberOfItems = $totalNumberOfItems;

return $this;
}

Expand All @@ -230,6 +281,7 @@ public function getTotalNumberOfPages(): int
public function setTotalNumberOfPages(int $totalNumberOfPages): static
{
$this->totalNumberOfPages = $totalNumberOfPages;

return $this;
}

Expand Down Expand Up @@ -265,6 +317,7 @@ public function getMeta(): array
public function setMeta(array $meta): static
{
$this->meta = $meta;

return $this;
}
}
Loading

0 comments on commit e279c84

Please sign in to comment.