From c6a9b9287e48a42c374a5f18f8fc25effb8f0a52 Mon Sep 17 00:00:00 2001 From: Bl00D4NGEL Date: Tue, 28 Nov 2023 15:15:52 +0100 Subject: [PATCH] refac: add/fix phpdoc fpr better generic support using static analysis --- src/Contracts/Domain/Paginator.php | 9 +++++---- src/Contracts/Domain/Repository.php | 12 +++++++----- src/Domain/Collection.php | 9 +++++---- src/Domain/ValueObject/Id.php | 2 +- src/Domain/ValueObject/Uuid.php | 2 +- src/Infrastructure/InMemory/Paginator.php | 9 +++++++++ src/Infrastructure/InMemory/Repository.php | 7 ++++--- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/Contracts/Domain/Paginator.php b/src/Contracts/Domain/Paginator.php index fab682e..452bf62 100644 --- a/src/Contracts/Domain/Paginator.php +++ b/src/Contracts/Domain/Paginator.php @@ -4,10 +4,11 @@ namespace GeekCell\Ddd\Contracts\Domain; -use Countable; -use IteratorAggregate; - -interface Paginator extends Countable, IteratorAggregate +/** + * @template T of object + * @extends \IteratorAggregate + */ +interface Paginator extends \Countable, \IteratorAggregate { /** * Returns the current page. diff --git a/src/Contracts/Domain/Repository.php b/src/Contracts/Domain/Repository.php index 439e5a6..4a68d37 100644 --- a/src/Contracts/Domain/Repository.php +++ b/src/Contracts/Domain/Repository.php @@ -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 + */ +interface Repository extends \Countable, \IteratorAggregate { /** * Returns a collection of items. * - * @return Collection + * @return Collection */ public function collect(): Collection; @@ -23,7 +25,7 @@ public function collect(): Collection; * @param int $itemsPerPage * @param int $currentPage * - * @return Paginator + * @return Paginator */ public function paginate( int $itemsPerPage, diff --git a/src/Domain/Collection.php b/src/Domain/Collection.php index 451450c..251bbf9 100644 --- a/src/Domain/Collection.php +++ b/src/Domain/Collection.php @@ -6,14 +6,15 @@ use Assert; +/** + * @template T of object + * @extends \IteratorAggregate + */ class Collection implements \ArrayAccess, \Countable, \IteratorAggregate { /** - * @template T of object - * @extends \IteratorAggregate - * * @param T[] $items - * @param class-string $itemType + * @param class-string|null $itemType * * @throws Assert\AssertionFailedException */ diff --git a/src/Domain/ValueObject/Id.php b/src/Domain/ValueObject/Id.php index 6e68a49..e4092e7 100644 --- a/src/Domain/ValueObject/Id.php +++ b/src/Domain/ValueObject/Id.php @@ -29,7 +29,7 @@ final public function __construct(int $id) /** * @inheritDoc */ - public function getValue(): mixed + public function getValue(): int { return $this->id; } diff --git a/src/Domain/ValueObject/Uuid.php b/src/Domain/ValueObject/Uuid.php index 27fa55a..0789b45 100644 --- a/src/Domain/ValueObject/Uuid.php +++ b/src/Domain/ValueObject/Uuid.php @@ -55,7 +55,7 @@ public function equals(ValueObjectInterface $object): bool /** * @inheritDoc */ - public function getValue(): mixed + public function getValue(): string { return $this->uuid; } diff --git a/src/Infrastructure/InMemory/Paginator.php b/src/Infrastructure/InMemory/Paginator.php index 8981a55..980fc54 100644 --- a/src/Infrastructure/InMemory/Paginator.php +++ b/src/Infrastructure/InMemory/Paginator.php @@ -11,8 +11,17 @@ use LimitIterator; use Traversable; +/** + * @template T of object + * @extends PaginatorInterface + */ class Paginator implements PaginatorInterface, ArrayAccess { + /** + * @param Collection $collection + * @param int $itemsPerPage + * @param int $currentPage + */ public function __construct( private readonly Collection $collection, private int $itemsPerPage, diff --git a/src/Infrastructure/InMemory/Repository.php b/src/Infrastructure/InMemory/Repository.php index 944e8b1..b73a48a 100644 --- a/src/Infrastructure/InMemory/Repository.php +++ b/src/Infrastructure/InMemory/Repository.php @@ -11,6 +11,10 @@ use GeekCell\Ddd\Infrastructure\InMemory\Paginator as InMemoryPaginator; use Traversable; +/** + * @template T of object + * @extends RepositoryInterface + */ abstract class Repository implements RepositoryInterface { /** @@ -19,9 +23,6 @@ abstract class Repository implements RepositoryInterface protected array $items = []; /** - * @template T of object - * @extends IteratorAggregate - * * @param class-string $itemType */ public function __construct(