Skip to content

Commit

Permalink
Merge pull request #18 from Bl00D4NGEL/enhance-generic-support
Browse files Browse the repository at this point in the history
Improve type definitions
  • Loading branch information
janvt authored Nov 29, 2023
2 parents 9023c1d + c6a9b92 commit 8e000ea
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
9 changes: 5 additions & 4 deletions src/Contracts/Domain/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace GeekCell\Ddd\Contracts\Domain;

use Countable;
use IteratorAggregate;

interface Paginator extends Countable, IteratorAggregate
/**
* @template T of object
* @extends \IteratorAggregate<T>
*/
interface Paginator extends \Countable, \IteratorAggregate
{
/**
* Returns the current page.
Expand Down
12 changes: 7 additions & 5 deletions src/Contracts/Domain/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

namespace GeekCell\Ddd\Contracts\Domain;

use Countable;
use GeekCell\Ddd\Domain\Collection;
use IteratorAggregate;

interface Repository extends Countable, IteratorAggregate
/**
* @template T of object
* @extends \IteratorAggregate<T>
*/
interface Repository extends \Countable, \IteratorAggregate
{
/**
* Returns a collection of items.
*
* @return Collection
* @return Collection<T>
*/
public function collect(): Collection;

Expand All @@ -23,7 +25,7 @@ public function collect(): Collection;
* @param int $itemsPerPage
* @param int $currentPage
*
* @return Paginator
* @return Paginator<T>
*/
public function paginate(
int $itemsPerPage,
Expand Down
9 changes: 5 additions & 4 deletions src/Domain/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use Assert;

/**
* @template T of object
* @extends \IteratorAggregate<T>
*/
class Collection implements \ArrayAccess, \Countable, \IteratorAggregate
{
/**
* @template T of object
* @extends \IteratorAggregate<T>
*
* @param T[] $items
* @param class-string<T> $itemType
* @param class-string<T>|null $itemType
*
* @throws Assert\AssertionFailedException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/ValueObject/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final public function __construct(int $id)
/**
* @inheritDoc
*/
public function getValue(): mixed
public function getValue(): int
{
return $this->id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/ValueObject/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function equals(ValueObjectInterface $object): bool
/**
* @inheritDoc
*/
public function getValue(): mixed
public function getValue(): string
{
return $this->uuid;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Infrastructure/InMemory/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@
use LimitIterator;
use Traversable;

/**
* @template T of object
* @extends PaginatorInterface<T>
*/
class Paginator implements PaginatorInterface, ArrayAccess
{
/**
* @param Collection<T> $collection
* @param int $itemsPerPage
* @param int $currentPage
*/
public function __construct(
private readonly Collection $collection,
private int $itemsPerPage,
Expand Down
7 changes: 4 additions & 3 deletions src/Infrastructure/InMemory/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
use GeekCell\Ddd\Infrastructure\InMemory\Paginator as InMemoryPaginator;
use Traversable;

/**
* @template T of object
* @extends RepositoryInterface<T>
*/
abstract class Repository implements RepositoryInterface
{
/**
Expand All @@ -19,9 +23,6 @@ abstract class Repository implements RepositoryInterface
protected array $items = [];

/**
* @template T of object
* @extends IteratorAggregate<T>
*
* @param class-string<T> $itemType
*/
public function __construct(
Expand Down

0 comments on commit 8e000ea

Please sign in to comment.