diff --git a/CHANGELOG.md b/CHANGELOG.md index f5aa5f7..2b1a76b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# 0.10.0 + +* chore: remove TIdentifier template as it feels superfluous in userland + # 0.9.3 * fix: renumbering of pages if anchored to the first page. diff --git a/packages/rekapager-api-platform/src/PagerFactoryInterface.php b/packages/rekapager-api-platform/src/PagerFactoryInterface.php index 2b3065a..eb24e0b 100644 --- a/packages/rekapager-api-platform/src/PagerFactoryInterface.php +++ b/packages/rekapager-api-platform/src/PagerFactoryInterface.php @@ -23,10 +23,9 @@ interface PagerFactoryInterface /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PageableInterface $pageable + * @param PageableInterface $pageable * @param array $context - * @return PageInterface + * @return PageInterface */ public function getPage( PageableInterface $pageable, @@ -37,10 +36,9 @@ public function getPage( /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PageableInterface $pageable + * @param PageableInterface $pageable * @param array $context - * @return TraversablePagerInterface + * @return TraversablePagerInterface */ public function createPager( PageableInterface $pageable, diff --git a/packages/rekapager-bundle/src/Contracts/ObjectPaginatorInterface.php b/packages/rekapager-bundle/src/Contracts/ObjectPaginatorInterface.php index 42da061..2ce3af0 100644 --- a/packages/rekapager-bundle/src/Contracts/ObjectPaginatorInterface.php +++ b/packages/rekapager-bundle/src/Contracts/ObjectPaginatorInterface.php @@ -23,7 +23,7 @@ interface ObjectPaginatorInterface { /** * @param null|TOptions $options - * @return PagerInterface + * @return PagerInterface */ public function paginate( object $object, diff --git a/packages/rekapager-bundle/src/Contracts/PagerFactoryInterface.php b/packages/rekapager-bundle/src/Contracts/PagerFactoryInterface.php index c72d34c..659c689 100644 --- a/packages/rekapager-bundle/src/Contracts/PagerFactoryInterface.php +++ b/packages/rekapager-bundle/src/Contracts/PagerFactoryInterface.php @@ -26,10 +26,9 @@ interface PagerFactoryInterface /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PageableInterface $pageable + * @param PageableInterface $pageable * @param TOptions|null $options - * @return PagerInterface + * @return PagerInterface * @throws OutOfBoundsException */ public function createPager( diff --git a/packages/rekapager-bundle/src/Exception/OutOfBoundsException.php b/packages/rekapager-bundle/src/Exception/OutOfBoundsException.php index 910ee1e..0541bb4 100644 --- a/packages/rekapager-bundle/src/Exception/OutOfBoundsException.php +++ b/packages/rekapager-bundle/src/Exception/OutOfBoundsException.php @@ -19,7 +19,7 @@ class OutOfBoundsException extends ContractsOutOfBoundsException { /** - * @param PagerInterface $pager + * @param PagerInterface $pager */ public function __construct( ContractsOutOfBoundsException $exception, @@ -34,7 +34,7 @@ public function __construct( } /** - * @return PagerInterface + * @return PagerInterface */ public function getPager(): PagerInterface { diff --git a/packages/rekapager-bundle/src/PagerFactory.php b/packages/rekapager-bundle/src/PagerFactory.php index 63b5536..1a0c442 100644 --- a/packages/rekapager-bundle/src/PagerFactory.php +++ b/packages/rekapager-bundle/src/PagerFactory.php @@ -116,6 +116,7 @@ public function createPager( ); try { + /** @psalm-suppress NoValue */ foreach ($pager->getCurrentPage() as $i); } catch (ContractsOutOfBoundsException $e) { throw new OutOfBoundsException($e, $pager, $options); @@ -125,9 +126,7 @@ public function createPager( } /** - * @template T of object - * @param PageableInterface $pageable - * @return T|null + * @param PageableInterface $pageable */ private function getPageIdentifier( PageableInterface $pageable, @@ -146,7 +145,6 @@ private function getPageIdentifier( ->getPageIdentifierEncoder($pageIdentifierClass) ->decode($pageIdentifier); - /** @var T */ return $pageIdentifier; } } diff --git a/packages/rekapager-bundle/src/Twig/RekapagerRuntime.php b/packages/rekapager-bundle/src/Twig/RekapagerRuntime.php index b5012e9..d3e0687 100644 --- a/packages/rekapager-bundle/src/Twig/RekapagerRuntime.php +++ b/packages/rekapager-bundle/src/Twig/RekapagerRuntime.php @@ -24,7 +24,7 @@ public function __construct( } /** - * @param PagerInterface $pager + * @param PagerInterface $pager * @param int<0,max>|null $proximity * @return string */ diff --git a/packages/rekapager-bundle/src/Twig/TwigPagerRenderer.php b/packages/rekapager-bundle/src/Twig/TwigPagerRenderer.php index e699d48..c84e181 100644 --- a/packages/rekapager-bundle/src/Twig/TwigPagerRenderer.php +++ b/packages/rekapager-bundle/src/Twig/TwigPagerRenderer.php @@ -25,7 +25,7 @@ public function __construct( } /** - * @param PagerInterface $pager + * @param PagerInterface $pager * @param int<0,max>|null $proximity */ public function render( diff --git a/packages/rekapager-contracts/src/NullPageInterface.php b/packages/rekapager-contracts/src/NullPageInterface.php index f34a4f7..bfd2058 100644 --- a/packages/rekapager-contracts/src/NullPageInterface.php +++ b/packages/rekapager-contracts/src/NullPageInterface.php @@ -19,8 +19,7 @@ * * @template TKey of array-key * @template T - * @template TIdentifier of object - * @extends PageInterface + * @extends PageInterface */ interface NullPageInterface extends PageInterface { diff --git a/packages/rekapager-contracts/src/PageInterface.php b/packages/rekapager-contracts/src/PageInterface.php index b1c198c..061a998 100644 --- a/packages/rekapager-contracts/src/PageInterface.php +++ b/packages/rekapager-contracts/src/PageInterface.php @@ -20,15 +20,12 @@ * * @template TKey of array-key * @template T - * @template TIdentifier of object * @extends \Traversable */ interface PageInterface extends \Traversable, \Countable { /** * Gets the page identifier - * - * @return TIdentifier */ public function getPageIdentifier(): object; @@ -41,12 +38,12 @@ public function getPageIdentifier(): object; public function getPageNumber(): ?int; /** - * @return self + * @return self */ public function withPageNumber(?int $pageNumber): self; /** - * @return PageableInterface + * @return PageableInterface */ public function getPageable(): PageableInterface; @@ -56,12 +53,12 @@ public function getPageable(): PageableInterface; public function getItemsPerPage(): int; /** - * @return null|PageInterface + * @return null|PageInterface */ public function getNextPage(): ?PageInterface; /** - * @return null|PageInterface + * @return null|PageInterface */ public function getPreviousPage(): ?PageInterface; @@ -69,7 +66,7 @@ public function getPreviousPage(): ?PageInterface; * Gets n next pages * * @param int<1,max> $numberOfPages - * @return array> + * @return array> */ public function getNextPages(int $numberOfPages): array; @@ -77,7 +74,7 @@ public function getNextPages(int $numberOfPages): array; * Gets n previous pages * * @param int<1,max> $numberOfPages - * @return array> + * @return array> */ public function getPreviousPages(int $numberOfPages): array; } diff --git a/packages/rekapager-contracts/src/PageableInterface.php b/packages/rekapager-contracts/src/PageableInterface.php index 65c6bd3..a24e7ae 100644 --- a/packages/rekapager-contracts/src/PageableInterface.php +++ b/packages/rekapager-contracts/src/PageableInterface.php @@ -18,33 +18,31 @@ * * @template TKey of array-key * @template T - * @template TIdentifier of object */ interface PageableInterface { /** - * @param TIdentifier $pageIdentifier - * @return PageInterface + * @return PageInterface */ - public function getPageByIdentifier(object $pageIdentifier): mixed; + public function getPageByIdentifier(object $pageIdentifier): PageInterface; /** - * @return class-string + * @return class-string */ public static function getPageIdentifierClass(): string; /** - * @return PageInterface + * @return PageInterface */ public function getFirstPage(): PageInterface; /** - * @return PageInterface|null + * @return PageInterface|null */ public function getLastPage(): ?PageInterface; /** - * @return \Traversable> + * @return \Traversable> */ public function getPages(): \Traversable; diff --git a/packages/rekapager-core/src/Contracts/PagerInterface.php b/packages/rekapager-core/src/Contracts/PagerInterface.php index a5bb572..ca3e126 100644 --- a/packages/rekapager-core/src/Contracts/PagerInterface.php +++ b/packages/rekapager-core/src/Contracts/PagerInterface.php @@ -16,7 +16,6 @@ /** * @template TKey of array-key * @template T - * @template TIdentifier of object */ interface PagerInterface { @@ -31,27 +30,27 @@ public function getProximity(): int; public function withProximity(int $proximity): static; /** - * @return PagerItemInterface + * @return PagerItemInterface */ public function getCurrentPage(): PagerItemInterface; /** - * @return PagerItemInterface|null + * @return PagerItemInterface|null */ public function getPreviousPage(): ?PagerItemInterface; /** - * @return PagerItemInterface|null + * @return PagerItemInterface|null */ public function getNextPage(): ?PagerItemInterface; /** - * @return PagerItemInterface|null + * @return PagerItemInterface|null */ public function getFirstPage(): ?PagerItemInterface; /** - * @return PagerItemInterface|null + * @return PagerItemInterface|null */ public function getLastPage(): ?PagerItemInterface; @@ -60,12 +59,12 @@ public function hasGapToFirstPage(): bool; public function hasGapToLastPage(): bool; /** - * @return iterable> + * @return iterable> */ public function getPreviousNeighboringPages(): iterable; /** - * @return iterable> + * @return iterable> */ public function getNextNeighboringPages(): iterable; } diff --git a/packages/rekapager-core/src/Contracts/PagerItemInterface.php b/packages/rekapager-core/src/Contracts/PagerItemInterface.php index 0831cfe..ebf3e6c 100644 --- a/packages/rekapager-core/src/Contracts/PagerItemInterface.php +++ b/packages/rekapager-core/src/Contracts/PagerItemInterface.php @@ -18,8 +18,7 @@ /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @extends PageInterface + * @extends PageInterface */ interface PagerItemInterface extends PageInterface { @@ -32,12 +31,12 @@ public function isDisabled(): bool; // /** - * @return null|PagerItemInterface + * @return null|PagerItemInterface */ public function getNextPage(): ?PagerItemInterface; /** - * @return null|PagerItemInterface + * @return null|PagerItemInterface */ public function getPreviousPage(): ?PagerItemInterface; @@ -45,7 +44,7 @@ public function getPreviousPage(): ?PagerItemInterface; * Gets n next pages * * @param int<1,max> $numberOfPages - * @return array> + * @return array> */ public function getNextPages(int $numberOfPages): array; @@ -53,7 +52,7 @@ public function getNextPages(int $numberOfPages): array; * Gets n previous pages * * @param int<1,max> $numberOfPages - * @return array> + * @return array> */ public function getPreviousPages(int $numberOfPages): array; } diff --git a/packages/rekapager-core/src/Contracts/TraversablePagerInterface.php b/packages/rekapager-core/src/Contracts/TraversablePagerInterface.php index 7f37425..b7cb56a 100644 --- a/packages/rekapager-core/src/Contracts/TraversablePagerInterface.php +++ b/packages/rekapager-core/src/Contracts/TraversablePagerInterface.php @@ -20,8 +20,7 @@ * * @template TKey of array-key * @template T - * @template TIdentifier of object - * @extends PagerInterface + * @extends PagerInterface * @extends \Traversable */ interface TraversablePagerInterface extends PagerInterface, \Traversable diff --git a/packages/rekapager-core/src/Pager/Internal/NullPageDecorator.php b/packages/rekapager-core/src/Pager/Internal/NullPageDecorator.php index df9621f..be11aee 100644 --- a/packages/rekapager-core/src/Pager/Internal/NullPageDecorator.php +++ b/packages/rekapager-core/src/Pager/Internal/NullPageDecorator.php @@ -21,15 +21,14 @@ * * @template TKey of array-key * @template T - * @template TIdentifier of object - * @implements NullPageInterface + * @implements NullPageInterface * @implements \IteratorAggregate * @internal */ final class NullPageDecorator implements NullPageInterface, \IteratorAggregate { /** - * @param PageInterface $page + * @param PageInterface $page */ public function __construct( private readonly PageInterface $page, diff --git a/packages/rekapager-core/src/Pager/Internal/PagerItem.php b/packages/rekapager-core/src/Pager/Internal/PagerItem.php index 75626a2..8e21353 100644 --- a/packages/rekapager-core/src/Pager/Internal/PagerItem.php +++ b/packages/rekapager-core/src/Pager/Internal/PagerItem.php @@ -24,8 +24,7 @@ * * @template TKey of array-key * @template T - * @template TIdentifier of object - * @implements PagerItemInterface + * @implements PagerItemInterface * @implements \IteratorAggregate * * @internal @@ -35,7 +34,7 @@ final class PagerItem implements PagerItemInterface, \IteratorAggregate private int|null|NullPageNumber $pageNumber; /** - * @param PageInterface $wrapped + * @param PageInterface $wrapped */ public function __construct( private PageInterface $wrapped, @@ -45,7 +44,7 @@ public function __construct( } /** - * @return self + * @return self */ public function withPageNumber(?int $pageNumber): self { @@ -146,9 +145,8 @@ public function getUrl(): ?string /** * @template TKey2 of array-key * @template T2 - * @template TIdentifier2 of object - * @param PageInterface $page - * @return PagerItem + * @param PageInterface $page + * @return PagerItem */ private function decorate(PageInterface $page): PagerItem { diff --git a/packages/rekapager-core/src/Pager/Internal/PagerUrlGeneratorInterface.php b/packages/rekapager-core/src/Pager/Internal/PagerUrlGeneratorInterface.php index 393f2e6..3f094d4 100644 --- a/packages/rekapager-core/src/Pager/Internal/PagerUrlGeneratorInterface.php +++ b/packages/rekapager-core/src/Pager/Internal/PagerUrlGeneratorInterface.php @@ -23,8 +23,7 @@ interface PagerUrlGeneratorInterface /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PageInterface $page + * @param PageInterface $page * @return string|null */ public function generateUrl(PageInterface $page): ?string; diff --git a/packages/rekapager-core/src/Pager/Internal/ProximityPager.php b/packages/rekapager-core/src/Pager/Internal/ProximityPager.php index f86c1c7..7e5e172 100644 --- a/packages/rekapager-core/src/Pager/Internal/ProximityPager.php +++ b/packages/rekapager-core/src/Pager/Internal/ProximityPager.php @@ -24,46 +24,45 @@ /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @implements PagerInterface + * @implements PagerInterface * @internal */ final class ProximityPager implements PagerInterface { - /** @var PageableInterface */ + /** @var PageableInterface */ private readonly PageableInterface $pageable; // // pager components // - /** @var PagerItem|null */ + /** @var PagerItem|null */ private ?PagerItem $previousPage = null; - /** @var PagerItem|null */ + /** @var PagerItem|null */ private ?PagerItem $firstPage = null; private bool $hasHiddenPagesBefore = false; - /** @var array> */ + /** @var array> */ private array $previousNeighboringPages = []; - /** @var PagerItem|null */ + /** @var PagerItem|null */ private ?PagerItem $currentPage = null; - /** @var array> */ + /** @var array> */ private array $nextNeighboringPages = []; private bool $hasHiddenPagesAfter = false; - /** @var PagerItem|null */ + /** @var PagerItem|null */ private ?PagerItem $lastPage = null; - /** @var PagerItem|null */ + /** @var PagerItem|null */ private ?PagerItem $nextPage = null; /** - * @param PageInterface $page + * @param PageInterface $page * @param int<1,max> $proximity */ public function __construct( @@ -391,9 +390,8 @@ public function getProximity(): int /** * @template TKey2 of array-key * @template T2 - * @template TIdentifier2 of object - * @param PageInterface $page - * @return PagerItem + * @param PageInterface $page + * @return PagerItem */ private function decorate(PageInterface $page): PagerItem { diff --git a/packages/rekapager-core/src/Pager/Internal/ZeroProximityPager.php b/packages/rekapager-core/src/Pager/Internal/ZeroProximityPager.php index 1bbb9a8..557fb6f 100644 --- a/packages/rekapager-core/src/Pager/Internal/ZeroProximityPager.php +++ b/packages/rekapager-core/src/Pager/Internal/ZeroProximityPager.php @@ -22,8 +22,7 @@ /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @implements PagerInterface + * @implements PagerInterface * @internal */ class ZeroProximityPager implements PagerInterface @@ -32,23 +31,23 @@ class ZeroProximityPager implements PagerInterface // pager components // - /** @var PagerItem|null */ + /** @var PagerItem|null */ private ?PagerItem $previousPage = null; - /** @var PagerItem|null */ + /** @var PagerItem|null */ private ?PagerItem $firstPage = null; - /** @var PagerItem|null */ + /** @var PagerItem|null */ private ?PagerItem $currentPage = null; - /** @var PagerItem|null */ + /** @var PagerItem|null */ private ?PagerItem $lastPage = null; - /** @var PagerItem|null */ + /** @var PagerItem|null */ private ?PagerItem $nextPage = null; /** - * @param PageInterface $page + * @param PageInterface $page */ public function __construct( PageInterface $page, @@ -112,9 +111,8 @@ public function getProximity(): int /** * @template TKey2 of array-key * @template T2 - * @template TIdentifier2 of object - * @param PageInterface|null $page - * @return PagerItem|null + * @param PageInterface|null $page + * @return PagerItem|null */ private function decorate(PageInterface|null $page): ?PagerItem { diff --git a/packages/rekapager-core/src/Pager/Pager.php b/packages/rekapager-core/src/Pager/Pager.php index 6240f79..669d349 100644 --- a/packages/rekapager-core/src/Pager/Pager.php +++ b/packages/rekapager-core/src/Pager/Pager.php @@ -28,19 +28,18 @@ /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @implements PagerInterface + * @implements PagerInterface */ final class Pager implements PagerInterface { /** - * @var PagerInterface|null + * @var PagerInterface|null */ private ?PagerInterface $pager = null; private PagerUrlGeneratorInterface $pagerUrlGenerator; /** - * @param PageInterface $page + * @param PageInterface $page * @param int<0,max> $proximity */ public function __construct( @@ -77,7 +76,7 @@ public function withProximity(int $proximity): static } /** - * @return PagerInterface + * @return PagerInterface */ private function getPager(): PagerInterface { diff --git a/packages/rekapager-core/src/Pager/TraversablePager.php b/packages/rekapager-core/src/Pager/TraversablePager.php index 6cc9176..0960c2c 100644 --- a/packages/rekapager-core/src/Pager/TraversablePager.php +++ b/packages/rekapager-core/src/Pager/TraversablePager.php @@ -22,14 +22,13 @@ * * @template TKey of array-key * @template T - * @template TIdentifier of object - * @implements TraversablePagerInterface + * @implements TraversablePagerInterface * @implements \IteratorAggregate */ final class TraversablePager implements TraversablePagerInterface, \IteratorAggregate { /** - * @param PagerInterface $decorated + * @param PagerInterface $decorated */ public function __construct( private PagerInterface $decorated diff --git a/packages/rekapager-keyset-pagination/src/Contracts/KeysetPageInterface.php b/packages/rekapager-keyset-pagination/src/Contracts/KeysetPageInterface.php index fdeb0c2..47d86de 100644 --- a/packages/rekapager-keyset-pagination/src/Contracts/KeysetPageInterface.php +++ b/packages/rekapager-keyset-pagination/src/Contracts/KeysetPageInterface.php @@ -20,7 +20,7 @@ * * @template TKey of array-key * @template T - * @extends PageInterface + * @extends PageInterface */ interface KeysetPageInterface extends PageInterface { diff --git a/packages/rekapager-keyset-pagination/src/Contracts/KeysetPageableInterface.php b/packages/rekapager-keyset-pagination/src/Contracts/KeysetPageableInterface.php index 74ae308..6097137 100644 --- a/packages/rekapager-keyset-pagination/src/Contracts/KeysetPageableInterface.php +++ b/packages/rekapager-keyset-pagination/src/Contracts/KeysetPageableInterface.php @@ -20,7 +20,7 @@ * * @template TKey of array-key * @template T - * @extends PageableInterface + * @extends PageableInterface */ interface KeysetPageableInterface extends PageableInterface { diff --git a/packages/rekapager-keyset-pagination/src/KeysetPageable.php b/packages/rekapager-keyset-pagination/src/KeysetPageable.php index 167ed26..5c09c20 100644 --- a/packages/rekapager-keyset-pagination/src/KeysetPageable.php +++ b/packages/rekapager-keyset-pagination/src/KeysetPageable.php @@ -13,6 +13,8 @@ namespace Rekalogika\Rekapager\Keyset; +use Rekalogika\Contracts\Rekapager\Exception\InvalidArgumentException; +use Rekalogika\Contracts\Rekapager\PageInterface; use Rekalogika\Contracts\Rekapager\Trait\TotalPagesTrait; use Rekalogika\Rekapager\Keyset\Contracts\BoundaryType; use Rekalogika\Rekapager\Keyset\Contracts\KeysetPageableInterface; @@ -129,8 +131,12 @@ public function getLastPage(): KeysetPageInterface ); } - public function getPageByIdentifier(mixed $pageIdentifier): mixed + public function getPageByIdentifier(object $pageIdentifier): PageInterface { + if (!$pageIdentifier instanceof KeysetPageIdentifier) { + throw new InvalidArgumentException('Invalid page identifier'); + } + return new KeysetPage( pageable: $this, adapter: $this->adapter, diff --git a/packages/rekapager-offset-pagination/src/Contracts/OffsetPageInterface.php b/packages/rekapager-offset-pagination/src/Contracts/OffsetPageInterface.php index cff956c..cf7b9bc 100644 --- a/packages/rekapager-offset-pagination/src/Contracts/OffsetPageInterface.php +++ b/packages/rekapager-offset-pagination/src/Contracts/OffsetPageInterface.php @@ -20,7 +20,7 @@ * * @template TKey of array-key * @template T - * @extends PageInterface + * @extends PageInterface */ interface OffsetPageInterface extends PageInterface { diff --git a/packages/rekapager-offset-pagination/src/Contracts/OffsetPageableInterface.php b/packages/rekapager-offset-pagination/src/Contracts/OffsetPageableInterface.php index 6c4ba20..0c1818a 100644 --- a/packages/rekapager-offset-pagination/src/Contracts/OffsetPageableInterface.php +++ b/packages/rekapager-offset-pagination/src/Contracts/OffsetPageableInterface.php @@ -20,7 +20,7 @@ * * @template TKey of array-key * @template T - * @extends PageableInterface + * @extends PageableInterface */ interface OffsetPageableInterface extends PageableInterface { diff --git a/packages/rekapager-offset-pagination/src/Internal/NullOffsetPage.php b/packages/rekapager-offset-pagination/src/Internal/NullOffsetPage.php index 513149c..eb319a5 100644 --- a/packages/rekapager-offset-pagination/src/Internal/NullOffsetPage.php +++ b/packages/rekapager-offset-pagination/src/Internal/NullOffsetPage.php @@ -22,14 +22,14 @@ * * @template TKey of array-key * @template T - * @implements NullPageInterface + * @implements NullPageInterface * @implements \IteratorAggregate * @internal */ final class NullOffsetPage implements NullPageInterface, \IteratorAggregate { /** - * @param PageableInterface $pageable + * @param PageableInterface $pageable * @param int<1,max> $pageNumber * @param int<1,max> $itemsPerPage */ diff --git a/packages/rekapager-offset-pagination/src/OffsetPageable.php b/packages/rekapager-offset-pagination/src/OffsetPageable.php index a61f1a8..d0d4589 100644 --- a/packages/rekapager-offset-pagination/src/OffsetPageable.php +++ b/packages/rekapager-offset-pagination/src/OffsetPageable.php @@ -13,6 +13,7 @@ namespace Rekalogika\Rekapager\Offset; +use Rekalogika\Contracts\Rekapager\Exception\InvalidArgumentException; use Rekalogika\Contracts\Rekapager\PageInterface; use Rekalogika\Contracts\Rekapager\Trait\TotalPagesTrait; use Rekalogika\Rekapager\Offset\Contracts\OffsetPageableInterface; @@ -102,8 +103,12 @@ public function getLastPage(): ?PageInterface return $this->getPageByIdentifier(new PageNumber($totalPages)); } - public function getPageByIdentifier(object $pageIdentifier): mixed + public function getPageByIdentifier(object $pageIdentifier): PageInterface { + if (!$pageIdentifier instanceof PageNumber) { + throw new InvalidArgumentException('Invalid page identifier'); + } + return new OffsetPage( pageable: $this, adapter: $this->adapter, diff --git a/packages/rekapager-pagerfanta-adapter/src/PagerfantaPageable.php b/packages/rekapager-pagerfanta-adapter/src/PagerfantaPageable.php index 54afeba..8fcfea2 100644 --- a/packages/rekapager-pagerfanta-adapter/src/PagerfantaPageable.php +++ b/packages/rekapager-pagerfanta-adapter/src/PagerfantaPageable.php @@ -47,7 +47,7 @@ public function __construct( ); } - public function getPageByIdentifier(object $pageIdentifier): mixed + public function getPageByIdentifier(object $pageIdentifier): PageInterface { return $this->pageable->getPageByIdentifier($pageIdentifier); } diff --git a/tests/src/App/Contracts/PageableGeneratorInterface.php b/tests/src/App/Contracts/PageableGeneratorInterface.php index 53a6288..cf70e78 100644 --- a/tests/src/App/Contracts/PageableGeneratorInterface.php +++ b/tests/src/App/Contracts/PageableGeneratorInterface.php @@ -19,7 +19,6 @@ /** * @template TKey of array-key * @template T - * @template TIdentifier of object */ #[AutoconfigureTag('rekalogika.rekapager.pageable_generator')] interface PageableGeneratorInterface extends \Countable @@ -31,7 +30,7 @@ public function getTitle(): string; * @param int<1,max> $itemsPerPage * @param bool|int<0,max> $count * @param int<1,max>|null $pageLimit - * @return PageableInterface + * @return PageableInterface */ public function generatePageable( int $itemsPerPage, diff --git a/tests/src/App/Controller/DemoController.php b/tests/src/App/Controller/DemoController.php index 9556d3f..2facf4b 100644 --- a/tests/src/App/Controller/DemoController.php +++ b/tests/src/App/Controller/DemoController.php @@ -29,7 +29,7 @@ class DemoController extends AbstractController { /** - * @param iterable> $pageableGenerators + * @param iterable> $pageableGenerators * @psalm-suppress DeprecatedClass */ public function __construct( @@ -57,7 +57,7 @@ public function index( /** @psalm-suppress InvalidArgument */ $pageableGenerators = iterator_to_array($this->pageableGenerators); - /** @var array> $pageableGenerators */ + /** @var array> $pageableGenerators */ if ($key === null) { foreach ($pageableGenerators as $pageableGenerator) { diff --git a/tests/src/App/PageableGenerator/KeysetPageableQueryBuilderAdapterQueryBuilder.php b/tests/src/App/PageableGenerator/KeysetPageableQueryBuilderAdapterQueryBuilder.php index a2eb2dd..b1b1517 100644 --- a/tests/src/App/PageableGenerator/KeysetPageableQueryBuilderAdapterQueryBuilder.php +++ b/tests/src/App/PageableGenerator/KeysetPageableQueryBuilderAdapterQueryBuilder.php @@ -23,7 +23,7 @@ use Rekalogika\Rekapager\Tests\App\Repository\PostRepository; /** - * @implements PageableGeneratorInterface + * @implements PageableGeneratorInterface */ class KeysetPageableQueryBuilderAdapterQueryBuilder implements PageableGeneratorInterface { diff --git a/tests/src/App/PageableGenerator/KeysetPageableSelectableAdapterCollection.php b/tests/src/App/PageableGenerator/KeysetPageableSelectableAdapterCollection.php index 3f36e6c..c90f550 100644 --- a/tests/src/App/PageableGenerator/KeysetPageableSelectableAdapterCollection.php +++ b/tests/src/App/PageableGenerator/KeysetPageableSelectableAdapterCollection.php @@ -24,7 +24,7 @@ use Rekalogika\Rekapager\Tests\App\Repository\UserRepository; /** - * @implements PageableGeneratorInterface + * @implements PageableGeneratorInterface */ class KeysetPageableSelectableAdapterCollection implements PageableGeneratorInterface { diff --git a/tests/src/App/PageableGenerator/KeysetPageableSelectableAdapterEntityRepository.php b/tests/src/App/PageableGenerator/KeysetPageableSelectableAdapterEntityRepository.php index 8ec8d42..8fbea8f 100644 --- a/tests/src/App/PageableGenerator/KeysetPageableSelectableAdapterEntityRepository.php +++ b/tests/src/App/PageableGenerator/KeysetPageableSelectableAdapterEntityRepository.php @@ -24,7 +24,7 @@ use Rekalogika\Rekapager\Tests\App\Repository\PostRepository; /** - * @implements PageableGeneratorInterface + * @implements PageableGeneratorInterface */ class KeysetPageableSelectableAdapterEntityRepository implements PageableGeneratorInterface { diff --git a/tests/src/App/PageableGenerator/OffsetPageableCollectionAdapterCollection.php b/tests/src/App/PageableGenerator/OffsetPageableCollectionAdapterCollection.php index b53397a..fbe0b70 100644 --- a/tests/src/App/PageableGenerator/OffsetPageableCollectionAdapterCollection.php +++ b/tests/src/App/PageableGenerator/OffsetPageableCollectionAdapterCollection.php @@ -24,7 +24,7 @@ use Rekalogika\Rekapager\Tests\App\Repository\UserRepository; /** - * @implements PageableGeneratorInterface + * @implements PageableGeneratorInterface */ class OffsetPageableCollectionAdapterCollection implements PageableGeneratorInterface { diff --git a/tests/src/App/PageableGenerator/OffsetPageablePagerfantaAdapterAdapter.php b/tests/src/App/PageableGenerator/OffsetPageablePagerfantaAdapterAdapter.php index 58b565c..a390588 100644 --- a/tests/src/App/PageableGenerator/OffsetPageablePagerfantaAdapterAdapter.php +++ b/tests/src/App/PageableGenerator/OffsetPageablePagerfantaAdapterAdapter.php @@ -24,7 +24,7 @@ use Rekalogika\Rekapager\Tests\App\Repository\UserRepository; /** - * @implements PageableGeneratorInterface + * @implements PageableGeneratorInterface */ class OffsetPageablePagerfantaAdapterAdapter implements PageableGeneratorInterface { diff --git a/tests/src/App/PageableGenerator/OffsetPageableSelectableAdapterCollection.php b/tests/src/App/PageableGenerator/OffsetPageableSelectableAdapterCollection.php index 600ec65..7267ea9 100644 --- a/tests/src/App/PageableGenerator/OffsetPageableSelectableAdapterCollection.php +++ b/tests/src/App/PageableGenerator/OffsetPageableSelectableAdapterCollection.php @@ -24,7 +24,7 @@ use Rekalogika\Rekapager\Tests\App\Repository\UserRepository; /** - * @implements PageableGeneratorInterface + * @implements PageableGeneratorInterface */ class OffsetPageableSelectableAdapterCollection implements PageableGeneratorInterface { diff --git a/tests/src/App/PageableGenerator/PagerfantaPageable_Pagerfanta_PagerfantaSelectableAdapter_Collection.php b/tests/src/App/PageableGenerator/PagerfantaPageable_Pagerfanta_PagerfantaSelectableAdapter_Collection.php index 3b5845b..8cc41f6 100644 --- a/tests/src/App/PageableGenerator/PagerfantaPageable_Pagerfanta_PagerfantaSelectableAdapter_Collection.php +++ b/tests/src/App/PageableGenerator/PagerfantaPageable_Pagerfanta_PagerfantaSelectableAdapter_Collection.php @@ -24,7 +24,7 @@ use Rekalogika\Rekapager\Tests\App\Repository\UserRepository; /** - * @implements PageableGeneratorInterface + * @implements PageableGeneratorInterface */ class PagerfantaPageable_Pagerfanta_PagerfantaSelectableAdapter_Collection implements PageableGeneratorInterface { diff --git a/tests/src/IntegrationTests/Pageable/PageableTestCase.php b/tests/src/IntegrationTests/Pageable/PageableTestCase.php index 535e99a..f0b42a2 100644 --- a/tests/src/IntegrationTests/Pageable/PageableTestCase.php +++ b/tests/src/IntegrationTests/Pageable/PageableTestCase.php @@ -49,7 +49,7 @@ protected function getPageLimit(): ?int } /** - * @return PageableInterface $pageable + * @return PageableInterface $pageable */ public function createPageableFromGenerator(string $pageableGeneratorClass): PageableInterface { diff --git a/tests/src/IntegrationTests/Pager/PagerTestCase.php b/tests/src/IntegrationTests/Pager/PagerTestCase.php index 9359b7c..7aebbe1 100644 --- a/tests/src/IntegrationTests/Pager/PagerTestCase.php +++ b/tests/src/IntegrationTests/Pager/PagerTestCase.php @@ -40,10 +40,8 @@ protected function getProximity(): int /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PageableInterface $pageable - * @param TIdentifier|null $pageIdentifier - * @return PagerInterface + * @param PageableInterface $pageable + * @return PagerInterface */ protected function createPagerFromPageable( PageableInterface $pageable, @@ -62,7 +60,7 @@ protected function createPagerFromPageable( ); /** - * @var PagerInterface + * @var PagerInterface * @phpstan-ignore-next-line */ return $pager; @@ -71,9 +69,8 @@ protected function createPagerFromPageable( /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PageInterface $page - * @return PagerInterface + * @param PageInterface $page + * @return PagerInterface */ protected function createPagerFromPage( PageInterface $page, @@ -85,7 +82,7 @@ protected function createPagerFromPage( ); /** - * @var PagerInterface + * @var PagerInterface * @phpstan-ignore-next-line */ return $pager; @@ -94,8 +91,7 @@ protected function createPagerFromPage( /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PagerInterface $pager + * @param PagerInterface $pager * @param array $previousPageNumbers * @param array $nextPageNumbers */ @@ -155,9 +151,8 @@ protected function assertPager( /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PageableInterface $pageable - * @return PageInterface + * @param PageableInterface $pageable + * @return PageInterface */ protected function getNthPageFromBeginning( PageableInterface $pageable, @@ -177,9 +172,8 @@ protected function getNthPageFromBeginning( /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PageableInterface $pageable - * @return PageInterface + * @param PageableInterface $pageable + * @return PageInterface */ protected function getNthPageFromEnd( PageableInterface $pageable, @@ -200,9 +194,8 @@ protected function getNthPageFromEnd( /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PageableInterface $pageable - * @return PageInterface + * @param PageableInterface $pageable + * @return PageInterface */ protected function getLastPageByIteration( PageableInterface $pageable, @@ -225,9 +218,8 @@ protected function getLastPageByIteration( /** * @template TKey of array-key * @template T - * @template TIdentifier of object - * @param PageableInterface $pageable - * @return PageInterface + * @param PageableInterface $pageable + * @return PageInterface */ protected function getNthPageFromEndByIteration( PageableInterface $pageable, diff --git a/tests/src/UnitTests/KeysetPageableTest.php b/tests/src/UnitTests/KeysetPageableTest.php index ff56a4e..89837a0 100644 --- a/tests/src/UnitTests/KeysetPageableTest.php +++ b/tests/src/UnitTests/KeysetPageableTest.php @@ -28,8 +28,8 @@ class KeysetPageableTest extends TestCase { /** - * @param PageableInterface $pageable - * @param PageInterface|null $page + * @param PageableInterface $pageable + * @param PageInterface|null $page * @param null|array $boundaryValues * @param array $values */ @@ -45,8 +45,10 @@ public static function assertBoundedPage( ): void { self::assertNotNull($page); - self::assertEquals($boundaryType, $page->getPageIdentifier()->getBoundaryType()); - self::assertEquals($boundaryValues, $page->getPageIdentifier()->getBoundaryValues()); + $pageIdentifier = $page->getPageIdentifier(); + self::assertInstanceOf(KeysetPageIdentifier::class, $pageIdentifier); + self::assertEquals($boundaryType, $pageIdentifier->getBoundaryType()); + self::assertEquals($boundaryValues, $pageIdentifier->getBoundaryValues()); self::assertEquals($values, array_map(fn (Entity $entity) => $entity->getId(), array_values(iterator_to_array($page)))); self::assertEquals($hasPreviousPage, null !== $page->getPreviousPage()); self::assertEquals($hasNextPage, null !== $page->getNextPage()); @@ -54,8 +56,10 @@ public static function assertBoundedPage( $bound = $page->getPageIdentifier(); $fromCollection = $pageable->getPageByIdentifier($bound); - self::assertEquals($boundaryType, $fromCollection->getPageIdentifier()->getBoundaryType()); - self::assertEquals($boundaryValues, $fromCollection->getPageIdentifier()->getBoundaryValues()); + $pageIdentifier = $fromCollection->getPageIdentifier(); + self::assertInstanceOf(KeysetPageIdentifier::class, $pageIdentifier); + self::assertEquals($boundaryType, $pageIdentifier->getBoundaryType()); + self::assertEquals($boundaryValues, $pageIdentifier->getBoundaryValues()); self::assertEquals($values, array_map(fn (Entity $entity) => $entity->getId(), array_values(iterator_to_array($fromCollection)))); self::assertEquals($hasPreviousPage, null !== $fromCollection->getPreviousPage()); self::assertEquals($hasNextPage, null !== $fromCollection->getNextPage()); diff --git a/tests/src/UnitTests/OffsetPageableTest.php b/tests/src/UnitTests/OffsetPageableTest.php index 75ee512..fe05b06 100644 --- a/tests/src/UnitTests/OffsetPageableTest.php +++ b/tests/src/UnitTests/OffsetPageableTest.php @@ -25,8 +25,8 @@ class OffsetPageableTest extends TestCase { /** - * @param PageableInterface $pageable - * @param PageInterface|null $page + * @param PageableInterface $pageable + * @param PageInterface|null $page * @param array $values * @param int<1,max> $pageNumber * @param int<1,max> $itemsPerPage