implement immutable datetime

This commit is contained in:
Dennis Eichhorn 2020-09-10 20:18:47 +02:00
parent 2287a43138
commit a2923fa173
2 changed files with 4 additions and 4 deletions

View File

@ -93,7 +93,7 @@ class NewsArticle implements \JsonSerializable, ArrayableInterface
* @var \DateTime * @var \DateTime
* @since 1.0.0 * @since 1.0.0
*/ */
private \DateTime $createdAt; private \DateTimeImmutable $createdAt;
/** /**
* Creator. * Creator.
@ -143,7 +143,7 @@ class NewsArticle implements \JsonSerializable, ArrayableInterface
public function __construct() public function __construct()
{ {
$this->createdBy = new NullAccount(); $this->createdBy = new NullAccount();
$this->createdAt = new \DateTime('now'); $this->createdAt = new \DateTimeImmutable('now');
$this->publish = new \DateTime('now'); $this->publish = new \DateTime('now');
} }
@ -232,7 +232,7 @@ class NewsArticle implements \JsonSerializable, ArrayableInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getCreatedAt() : \DateTime public function getCreatedAt() : \DateTimeInterface
{ {
return $this->createdAt; return $this->createdAt;
} }

View File

@ -51,7 +51,7 @@ final class NewsArticleMapper extends DataMapperAbstract
'news_type' => ['name' => 'news_type', 'type' => 'int', 'internal' => 'type'], 'news_type' => ['name' => 'news_type', 'type' => 'int', 'internal' => 'type'],
'news_featured' => ['name' => 'news_featured', 'type' => 'bool', 'internal' => 'featured'], 'news_featured' => ['name' => 'news_featured', 'type' => 'bool', 'internal' => 'featured'],
'news_comment_list' => ['name' => 'news_comment_list', 'type' => 'int', 'internal' => 'comments'], 'news_comment_list' => ['name' => 'news_comment_list', 'type' => 'int', 'internal' => 'comments'],
'news_created_at' => ['name' => 'news_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], 'news_created_at' => ['name' => 'news_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
'news_created_by' => ['name' => 'news_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], 'news_created_by' => ['name' => 'news_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
]; ];