Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove TIdentifier template as it feels superfluous in userland #70

Merged
merged 1 commit into from
Jun 10, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 4 additions & 6 deletions packages/rekapager-api-platform/src/PagerFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ interface PagerFactoryInterface
/**
* @template TKey of array-key
* @template T
* @template TIdentifier of object
* @param PageableInterface<TKey,T,TIdentifier> $pageable
* @param PageableInterface<TKey,T> $pageable
* @param array<array-key,mixed> $context
* @return PageInterface<TKey,T,TIdentifier>
* @return PageInterface<TKey,T>
*/
public function getPage(
PageableInterface $pageable,
Expand All @@ -37,10 +36,9 @@ public function getPage(
/**
* @template TKey of array-key
* @template T
* @template TIdentifier of object
* @param PageableInterface<TKey,T,TIdentifier> $pageable
* @param PageableInterface<TKey,T> $pageable
* @param array<array-key,mixed> $context
* @return TraversablePagerInterface<TKey,T,TIdentifier>
* @return TraversablePagerInterface<TKey,T>
*/
public function createPager(
PageableInterface $pageable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ObjectPaginatorInterface
{
/**
* @param null|TOptions $options
* @return PagerInterface<array-key,mixed,object>
* @return PagerInterface<array-key,mixed>
*/
public function paginate(
object $object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ interface PagerFactoryInterface
/**
* @template TKey of array-key
* @template T
* @template TIdentifier of object
* @param PageableInterface<TKey,T,TIdentifier> $pageable
* @param PageableInterface<TKey,T> $pageable
* @param TOptions|null $options
* @return PagerInterface<TKey,T,TIdentifier>
* @return PagerInterface<TKey,T>
* @throws OutOfBoundsException
*/
public function createPager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class OutOfBoundsException extends ContractsOutOfBoundsException
{
/**
* @param PagerInterface<array-key,mixed,object> $pager
* @param PagerInterface<array-key,mixed> $pager
*/
public function __construct(
ContractsOutOfBoundsException $exception,
Expand All @@ -34,7 +34,7 @@ public function __construct(
}

/**
* @return PagerInterface<array-key,mixed,object>
* @return PagerInterface<array-key,mixed>
*/
public function getPager(): PagerInterface
{
Expand Down
6 changes: 2 additions & 4 deletions packages/rekapager-bundle/src/PagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -125,9 +126,7 @@ public function createPager(
}

/**
* @template T of object
* @param PageableInterface<array-key,mixed,T> $pageable
* @return T|null
* @param PageableInterface<array-key,mixed> $pageable
*/
private function getPageIdentifier(
PageableInterface $pageable,
Expand All @@ -146,7 +145,6 @@ private function getPageIdentifier(
->getPageIdentifierEncoder($pageIdentifierClass)
->decode($pageIdentifier);

/** @var T */
return $pageIdentifier;
}
}
2 changes: 1 addition & 1 deletion packages/rekapager-bundle/src/Twig/RekapagerRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
}

/**
* @param PagerInterface<array-key,mixed,object> $pager
* @param PagerInterface<array-key,mixed> $pager
* @param int<0,max>|null $proximity
* @return string
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/rekapager-bundle/src/Twig/TwigPagerRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
}

/**
* @param PagerInterface<array-key,mixed,object> $pager
* @param PagerInterface<array-key,mixed> $pager
* @param int<0,max>|null $proximity
*/
public function render(
Expand Down
3 changes: 1 addition & 2 deletions packages/rekapager-contracts/src/NullPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
*
* @template TKey of array-key
* @template T
* @template TIdentifier of object
* @extends PageInterface<TKey,T,TIdentifier>
* @extends PageInterface<TKey,T>
*/
interface NullPageInterface extends PageInterface
{
Expand Down
15 changes: 6 additions & 9 deletions packages/rekapager-contracts/src/PageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
*
* @template TKey of array-key
* @template T
* @template TIdentifier of object
* @extends \Traversable<TKey,T>
*/
interface PageInterface extends \Traversable, \Countable
{
/**
* Gets the page identifier
*
* @return TIdentifier
*/
public function getPageIdentifier(): object;

Expand All @@ -41,12 +38,12 @@ public function getPageIdentifier(): object;
public function getPageNumber(): ?int;

/**
* @return self<TKey,T,TIdentifier>
* @return self<TKey,T>
*/
public function withPageNumber(?int $pageNumber): self;

/**
* @return PageableInterface<TKey,T,TIdentifier>
* @return PageableInterface<TKey,T>
*/
public function getPageable(): PageableInterface;

Expand All @@ -56,28 +53,28 @@ public function getPageable(): PageableInterface;
public function getItemsPerPage(): int;

/**
* @return null|PageInterface<TKey,T,TIdentifier>
* @return null|PageInterface<TKey,T>
*/
public function getNextPage(): ?PageInterface;

/**
* @return null|PageInterface<TKey,T,TIdentifier>
* @return null|PageInterface<TKey,T>
*/
public function getPreviousPage(): ?PageInterface;

/**
* Gets n next pages
*
* @param int<1,max> $numberOfPages
* @return array<int,PageInterface<TKey,T,TIdentifier>>
* @return array<int,PageInterface<TKey,T>>
*/
public function getNextPages(int $numberOfPages): array;

/**
* Gets n previous pages
*
* @param int<1,max> $numberOfPages
* @return array<int,PageInterface<TKey,T,TIdentifier>>
* @return array<int,PageInterface<TKey,T>>
*/
public function getPreviousPages(int $numberOfPages): array;
}
14 changes: 6 additions & 8 deletions packages/rekapager-contracts/src/PageableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,31 @@
*
* @template TKey of array-key
* @template T
* @template TIdentifier of object
*/
interface PageableInterface
{
/**
* @param TIdentifier $pageIdentifier
* @return PageInterface<TKey,T,TIdentifier>
* @return PageInterface<TKey,T>
*/
public function getPageByIdentifier(object $pageIdentifier): mixed;
public function getPageByIdentifier(object $pageIdentifier): PageInterface;

/**
* @return class-string<TIdentifier>
* @return class-string
*/
public static function getPageIdentifierClass(): string;

/**
* @return PageInterface<TKey,T,TIdentifier>
* @return PageInterface<TKey,T>
*/
public function getFirstPage(): PageInterface;

/**
* @return PageInterface<TKey,T,TIdentifier>|null
* @return PageInterface<TKey,T>|null
*/
public function getLastPage(): ?PageInterface;

/**
* @return \Traversable<PageInterface<TKey,T,TIdentifier>>
* @return \Traversable<PageInterface<TKey,T>>
*/
public function getPages(): \Traversable;

Expand Down
15 changes: 7 additions & 8 deletions packages/rekapager-core/src/Contracts/PagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/**
* @template TKey of array-key
* @template T
* @template TIdentifier of object
*/
interface PagerInterface
{
Expand All @@ -31,27 +30,27 @@ public function getProximity(): int;
public function withProximity(int $proximity): static;

/**
* @return PagerItemInterface<TKey,T,TIdentifier>
* @return PagerItemInterface<TKey,T>
*/
public function getCurrentPage(): PagerItemInterface;

/**
* @return PagerItemInterface<TKey,T,TIdentifier>|null
* @return PagerItemInterface<TKey,T>|null
*/
public function getPreviousPage(): ?PagerItemInterface;

/**
* @return PagerItemInterface<TKey,T,TIdentifier>|null
* @return PagerItemInterface<TKey,T>|null
*/
public function getNextPage(): ?PagerItemInterface;

/**
* @return PagerItemInterface<TKey,T,TIdentifier>|null
* @return PagerItemInterface<TKey,T>|null
*/
public function getFirstPage(): ?PagerItemInterface;

/**
* @return PagerItemInterface<TKey,T,TIdentifier>|null
* @return PagerItemInterface<TKey,T>|null
*/
public function getLastPage(): ?PagerItemInterface;

Expand All @@ -60,12 +59,12 @@ public function hasGapToFirstPage(): bool;
public function hasGapToLastPage(): bool;

/**
* @return iterable<int,PagerItemInterface<TKey,T,TIdentifier>>
* @return iterable<int,PagerItemInterface<TKey,T>>
*/
public function getPreviousNeighboringPages(): iterable;

/**
* @return iterable<int,PagerItemInterface<TKey,T,TIdentifier>>
* @return iterable<int,PagerItemInterface<TKey,T>>
*/
public function getNextNeighboringPages(): iterable;
}
11 changes: 5 additions & 6 deletions packages/rekapager-core/src/Contracts/PagerItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
/**
* @template TKey of array-key
* @template T
* @template TIdentifier of object
* @extends PageInterface<TKey,T,TIdentifier>
* @extends PageInterface<TKey,T>
*/
interface PagerItemInterface extends PageInterface
{
Expand All @@ -32,28 +31,28 @@ public function isDisabled(): bool;
//

/**
* @return null|PagerItemInterface<TKey,T,TIdentifier>
* @return null|PagerItemInterface<TKey,T>
*/
public function getNextPage(): ?PagerItemInterface;

/**
* @return null|PagerItemInterface<TKey,T,TIdentifier>
* @return null|PagerItemInterface<TKey,T>
*/
public function getPreviousPage(): ?PagerItemInterface;

/**
* Gets n next pages
*
* @param int<1,max> $numberOfPages
* @return array<int,PagerItemInterface<TKey,T,TIdentifier>>
* @return array<int,PagerItemInterface<TKey,T>>
*/
public function getNextPages(int $numberOfPages): array;

/**
* Gets n previous pages
*
* @param int<1,max> $numberOfPages
* @return array<int,PagerItemInterface<TKey,T,TIdentifier>>
* @return array<int,PagerItemInterface<TKey,T>>
*/
public function getPreviousPages(int $numberOfPages): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
*
* @template TKey of array-key
* @template T
* @template TIdentifier of object
* @extends PagerInterface<TKey,T,TIdentifier>
* @extends PagerInterface<TKey,T>
* @extends \Traversable<TKey,T>
*/
interface TraversablePagerInterface extends PagerInterface, \Traversable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
*
* @template TKey of array-key
* @template T
* @template TIdentifier of object
* @implements NullPageInterface<TKey,T,TIdentifier>
* @implements NullPageInterface<TKey,T>
* @implements \IteratorAggregate<TKey,T>
* @internal
*/
final class NullPageDecorator implements NullPageInterface, \IteratorAggregate
{
/**
* @param PageInterface<TKey,T,TIdentifier> $page
* @param PageInterface<TKey,T> $page
*/
public function __construct(
private readonly PageInterface $page,
Expand Down
Loading
Loading