Skip to content

Commit 8e000ea

Browse files
author
janvt
authored
Merge pull request #18 from Bl00D4NGEL/enhance-generic-support
Improve type definitions
2 parents 9023c1d + c6a9b92 commit 8e000ea

File tree

7 files changed

+32
-18
lines changed

7 files changed

+32
-18
lines changed

src/Contracts/Domain/Paginator.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
namespace GeekCell\Ddd\Contracts\Domain;
66

7-
use Countable;
8-
use IteratorAggregate;
9-
10-
interface Paginator extends Countable, IteratorAggregate
7+
/**
8+
* @template T of object
9+
* @extends \IteratorAggregate<T>
10+
*/
11+
interface Paginator extends \Countable, \IteratorAggregate
1112
{
1213
/**
1314
* Returns the current page.

src/Contracts/Domain/Repository.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
namespace GeekCell\Ddd\Contracts\Domain;
66

7-
use Countable;
87
use GeekCell\Ddd\Domain\Collection;
9-
use IteratorAggregate;
108

11-
interface Repository extends Countable, IteratorAggregate
9+
/**
10+
* @template T of object
11+
* @extends \IteratorAggregate<T>
12+
*/
13+
interface Repository extends \Countable, \IteratorAggregate
1214
{
1315
/**
1416
* Returns a collection of items.
1517
*
16-
* @return Collection
18+
* @return Collection<T>
1719
*/
1820
public function collect(): Collection;
1921

@@ -23,7 +25,7 @@ public function collect(): Collection;
2325
* @param int $itemsPerPage
2426
* @param int $currentPage
2527
*
26-
* @return Paginator
28+
* @return Paginator<T>
2729
*/
2830
public function paginate(
2931
int $itemsPerPage,

src/Domain/Collection.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
use Assert;
88

9+
/**
10+
* @template T of object
11+
* @extends \IteratorAggregate<T>
12+
*/
913
class Collection implements \ArrayAccess, \Countable, \IteratorAggregate
1014
{
1115
/**
12-
* @template T of object
13-
* @extends \IteratorAggregate<T>
14-
*
1516
* @param T[] $items
16-
* @param class-string<T> $itemType
17+
* @param class-string<T>|null $itemType
1718
*
1819
* @throws Assert\AssertionFailedException
1920
*/

src/Domain/ValueObject/Id.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final public function __construct(int $id)
2929
/**
3030
* @inheritDoc
3131
*/
32-
public function getValue(): mixed
32+
public function getValue(): int
3333
{
3434
return $this->id;
3535
}

src/Domain/ValueObject/Uuid.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function equals(ValueObjectInterface $object): bool
5555
/**
5656
* @inheritDoc
5757
*/
58-
public function getValue(): mixed
58+
public function getValue(): string
5959
{
6060
return $this->uuid;
6161
}

src/Infrastructure/InMemory/Paginator.php

+9
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@
1111
use LimitIterator;
1212
use Traversable;
1313

14+
/**
15+
* @template T of object
16+
* @extends PaginatorInterface<T>
17+
*/
1418
class Paginator implements PaginatorInterface, ArrayAccess
1519
{
20+
/**
21+
* @param Collection<T> $collection
22+
* @param int $itemsPerPage
23+
* @param int $currentPage
24+
*/
1625
public function __construct(
1726
private readonly Collection $collection,
1827
private int $itemsPerPage,

src/Infrastructure/InMemory/Repository.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
use GeekCell\Ddd\Infrastructure\InMemory\Paginator as InMemoryPaginator;
1212
use Traversable;
1313

14+
/**
15+
* @template T of object
16+
* @extends RepositoryInterface<T>
17+
*/
1418
abstract class Repository implements RepositoryInterface
1519
{
1620
/**
@@ -19,9 +23,6 @@ abstract class Repository implements RepositoryInterface
1923
protected array $items = [];
2024

2125
/**
22-
* @template T of object
23-
* @extends IteratorAggregate<T>
24-
*
2526
* @param class-string<T> $itemType
2627
*/
2728
public function __construct(

0 commit comments

Comments
 (0)