This commit is contained in:
Dominik Liebler
2021-04-12 14:04:45 +02:00
parent 5c5d453506
commit 4678b5d86f
50 changed files with 992 additions and 1430 deletions

View File

@@ -4,11 +4,6 @@ namespace DesignPatterns\More\Repository\Domain;
class Post
{
private PostId $id;
private PostStatus $status;
private string $title;
private string $text;
public static function draft(PostId $id, string $title, string $text): Post
{
return new self(
@@ -29,12 +24,12 @@ class Post
);
}
private function __construct(PostId $id, PostStatus $status, string $title, string $text)
{
$this->id = $id;
$this->status = $status;
$this->text = $text;
$this->title = $title;
private function __construct(
private PostId $id,
private PostStatus $status,
private string $title,
private string $text
) {
}
public function getId(): PostId

View File

@@ -13,8 +13,6 @@ use InvalidArgumentException;
*/
class PostId
{
private int $id;
public static function fromInt(int $id): PostId
{
self::ensureIsValid($id);
@@ -22,9 +20,8 @@ class PostId
return new self($id);
}
private function __construct(int $id)
private function __construct(private int $id)
{
$this->id = $id;
}
public function toInt(): int

View File

@@ -21,9 +21,6 @@ class PostStatus
self::STATE_PUBLISHED_ID => self::STATE_PUBLISHED,
];
private int $id;
private string $name;
public static function fromInt(int $statusId)
{
self::ensureIsValidId($statusId);
@@ -43,10 +40,8 @@ class PostStatus
return new self($state, $status);
}
private function __construct(int $id, string $name)
private function __construct(private int $id, private string $name)
{
$this->id = $id;
$this->name = $name;
}
public function toInt(): int

View File

@@ -17,11 +17,8 @@ use DesignPatterns\More\Repository\Domain\PostId;
*/
class PostRepository
{
private Persistence $persistence;
public function __construct(Persistence $persistence)
public function __construct(private Persistence $persistence)
{
$this->persistence = $persistence;
}
public function generateId(): PostId