Add setters for the existing entities.
This commit is contained in:
parent
8d7bcd0c2a
commit
db1e7e04f6
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user