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,15 +4,13 @@ namespace DesignPatterns\More\EAV;
use SplObjectStorage;
class Attribute
class Attribute implements \Stringable
{
private SplObjectStorage $values;
private string $name;
public function __construct(string $name)
public function __construct(private string $name)
{
$this->values = new SplObjectStorage();
$this->name = $name;
}
public function addValue(Value $value)

View File

@@ -4,7 +4,7 @@ namespace DesignPatterns\More\EAV;
use SplObjectStorage;
class Entity
class Entity implements \Stringable
{
/**
* @var SplObjectStorage<Value,Value>
@@ -12,19 +12,11 @@ class Entity
private $values;
/**
* @var string
*/
private string $name;
/**
* @param string $name
* @param Value[] $values
*/
public function __construct(string $name, $values)
public function __construct(private string $name, $values)
{
/** @var SplObjectStorage<Value,Value> values */
$this->values = new SplObjectStorage();
$this->name = $name;
foreach ($values as $value) {
$this->values->attach($value);

View File

@@ -2,16 +2,10 @@
namespace DesignPatterns\More\EAV;
class Value
class Value implements \Stringable
{
private Attribute $attribute;
private string $name;
public function __construct(Attribute $attribute, string $name)
public function __construct(private Attribute $attribute, private string $name)
{
$this->name = $name;
$this->attribute = $attribute;
$attribute->addValue($this);
}

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