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

Improve type definitions #18

Merged
merged 1 commit into from
Nov 29, 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: 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