Skip to content

Feat: Genericly implement ArrayAccess for Collection and Paginator #23

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

Merged
merged 1 commit into from
Dec 19, 2023
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
9 changes: 3 additions & 6 deletions src/Domain/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

/**
* @template T of object
* @extends \IteratorAggregate<T>
* @implements \IteratorAggregate<T>
* @implements \ArrayAccess<mixed, T>
*/
class Collection implements \ArrayAccess, \Countable, \IteratorAggregate
{
/**
* @param T[] $items
* @param class-string<T>|null $itemType
*
* @throws Assert\AssertionFailedException
*/
final public function __construct(
private readonly array $items = [],
Expand All @@ -31,10 +30,8 @@ final public function __construct(
* Add one or more items to the collection. It **does not** modify the
* current collection, but returns a new one.
*
* @param mixed $item One or more items to add to the collection.
* @param mixed $item One or more items to add to the collection.
* @return static
*
* @throws Assert\AssertionFailedException
*/
public function add(mixed $item): static
{
Expand Down
3 changes: 2 additions & 1 deletion src/Infrastructure/InMemory/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

/**
* @template T of object
* @extends PaginatorInterface<T>
* @implements PaginatorInterface<T>
* @implements ArrayAccess<mixed, T>
*/
class Paginator implements PaginatorInterface, ArrayAccess
{
Expand Down