diff --git a/app/src/Domain/Entity.php b/app/src/Domain/Entity.php index d88b7f4..dd4d989 100644 --- a/app/src/Domain/Entity.php +++ b/app/src/Domain/Entity.php @@ -7,9 +7,14 @@ use DateTimeImmutable; trait Entity { - protected int $id; - protected DateTimeImmutable $createdAt; - protected DateTime $updatedAt; + protected ?int $id; + protected ?DateTimeImmutable $createdAt; + protected ?DateTime $updatedAt; + + public function isNew(): bool + { + return (bool) $this->id; + } public function setId(int $id): void { diff --git a/app/src/Domain/Entity/Channel.php b/app/src/Domain/Entity/Channel.php index e640bbc..c7f6cc5 100644 --- a/app/src/Domain/Entity/Channel.php +++ b/app/src/Domain/Entity/Channel.php @@ -10,7 +10,7 @@ class Channel public function __construct( private string $name, - private ?string $description = '', + private string $description, private ?string $link = '', private ?string $language = '', private ?string $copyright = '', @@ -32,16 +32,45 @@ class Channel return $this->link; } + public function setLink(string $link): Channel + { + $this->link = $link; + return $this; + } + public function getLanguage(): string { return $this->language; } + public function setLanguage(string $language): Channel + { + $this->language = $language; + return $this; + } + public function getCopyright(): string { return $this->copyright; } + public function setCopyright(string $copyright): Channel + { + $this->copyright = $copyright; + return $this; + } + + public function isExplicit(): bool + { + return $this->explicit; + } + + public function setExplicit(bool $explicit): Channel + { + $this->explicit = $explicit; + return $this; + } + /** * @param array $props The properties of the Channel model * @return Channel diff --git a/app/src/Domain/Entity/User.php b/app/src/Domain/Entity/User.php index 3d4eb2c..b34f5fa 100644 --- a/app/src/Domain/Entity/User.php +++ b/app/src/Domain/Entity/User.php @@ -19,24 +19,32 @@ class User return $this->email; } + public function setEmail(string $email): User + { + $this->email = $email; + return $this; + } + public function getPassword(): string { return $this->password; } + public function setPassword(string $password): User + { + $this->password = $password; + return $this; + } + public function getName(): string { return $this->name; } - /** - * If the `id` property exists, we can assume this entity already exists. - * - * @return bool - */ - public function isNew(): bool + public function setName(string $name): User { - return (bool) $this->getId(); + $this->name = $name; + return $this; } /** @@ -45,18 +53,19 @@ class User */ public static function fromArray(array $props): User { - $user = new self( - $props['email'], - $props['password'], - $props['name'] - ); + $user = new self($props['email'], $props['password'], $props['name']); if ($props['id']) { $user->setId($props['id']); } - $user->setCreatedAt($props['createdAt']); - $user->setUpdatedAt($props['updatedAt']); + if ($props['createdAt']) { + $user->setCreatedAt($props['createdAt']); + } + + if ($props['updatedAt']) { + $user->setUpdatedAt($props['updatedAt']); + } return $user; }