mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-30 19:50:12 +02:00
PHP8
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user