mirror of
https://github.com/Karaka-Management/oms-QA.git
synced 2026-02-18 08:48:39 +00:00
implement immutable datetime
This commit is contained in:
parent
49e97dc646
commit
803d31cd56
|
|
@ -83,7 +83,7 @@ class QAAnswer implements \JsonSerializable
|
||||||
* @var \DateTime
|
* @var \DateTime
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private \DateTime $createdAt;
|
private \DateTimeImmutable $createdAt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|
@ -92,7 +92,7 @@ class QAAnswer implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->createdAt = new \DateTime('now');
|
$this->createdAt = new \DateTimeImmutable('now');
|
||||||
$this->createdBy = new NullAccount();
|
$this->createdBy = new NullAccount();
|
||||||
$this->question = new NullQAQuestion();
|
$this->question = new NullQAQuestion();
|
||||||
}
|
}
|
||||||
|
|
@ -246,7 +246,7 @@ class QAAnswer implements \JsonSerializable
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getCreatedAt() : \DateTime
|
public function getCreatedAt() : \DateTimeInterface
|
||||||
{
|
{
|
||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ final class QAAnswerMapper extends DataMapperAbstract
|
||||||
'qa_answer_status' => ['name' => 'qa_answer_status', 'type' => 'int', 'internal' => 'status'],
|
'qa_answer_status' => ['name' => 'qa_answer_status', 'type' => 'int', 'internal' => 'status'],
|
||||||
'qa_answer_accepted' => ['name' => 'qa_answer_accepted', 'type' => 'bool', 'internal' => 'isAccepted'],
|
'qa_answer_accepted' => ['name' => 'qa_answer_accepted', 'type' => 'bool', 'internal' => 'isAccepted'],
|
||||||
'qa_answer_created_by' => ['name' => 'qa_answer_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
'qa_answer_created_by' => ['name' => 'qa_answer_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||||
'qa_answer_created_at' => ['name' => 'qa_answer_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true],
|
'qa_answer_created_at' => ['name' => 'qa_answer_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ class QAQuestion implements \JsonSerializable
|
||||||
* @var \DateTime
|
* @var \DateTime
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private \DateTime $createdAt;
|
private \DateTimeImmutable $createdAt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Badges.
|
* Badges.
|
||||||
|
|
@ -109,7 +109,7 @@ class QAQuestion implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->createdAt = new \DateTime('now');
|
$this->createdAt = new \DateTimeImmutable('now');
|
||||||
$this->createdBy = new NullAccount();
|
$this->createdBy = new NullAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -324,7 +324,7 @@ class QAQuestion implements \JsonSerializable
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getCreatedAt() : \DateTime
|
public function getCreatedAt() : \DateTimeInterface
|
||||||
{
|
{
|
||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ final class QAQuestionMapper extends DataMapperAbstract
|
||||||
'qa_question_status' => ['name' => 'qa_question_status', 'type' => 'int', 'internal' => 'status'],
|
'qa_question_status' => ['name' => 'qa_question_status', 'type' => 'int', 'internal' => 'status'],
|
||||||
'qa_question_category' => ['name' => 'qa_question_category', 'type' => 'int', 'internal' => 'category'],
|
'qa_question_category' => ['name' => 'qa_question_category', 'type' => 'int', 'internal' => 'category'],
|
||||||
'qa_question_created_by' => ['name' => 'qa_question_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
'qa_question_created_by' => ['name' => 'qa_question_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||||
'qa_question_created_at' => ['name' => 'qa_question_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true],
|
'qa_question_created_at' => ['name' => 'qa_question_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class QAAnswerTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertFalse($answer->isAccepted());
|
self::assertFalse($answer->isAccepted());
|
||||||
self::assertEquals(QAAnswerStatus::ACTIVE, $answer->getStatus());
|
self::assertEquals(QAAnswerStatus::ACTIVE, $answer->getStatus());
|
||||||
self::assertEquals(0, $answer->getCreatedBy()->getId());
|
self::assertEquals(0, $answer->getCreatedBy()->getId());
|
||||||
self::assertInstanceOf('\DateTime', $answer->getCreatedAt());
|
self::assertInstanceOf('\DateTimeImmutable', $answer->getCreatedAt());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetGet() : void
|
public function testSetGet() : void
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class QAQuestionTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals(0, $question->getCategory()->getId());
|
self::assertEquals(0, $question->getCategory()->getId());
|
||||||
self::assertEquals('', $question->getLanguage());
|
self::assertEquals('', $question->getLanguage());
|
||||||
self::assertEquals(0, $question->getCreatedBy()->getId());
|
self::assertEquals(0, $question->getCreatedBy()->getId());
|
||||||
self::assertInstanceOf('\DateTime', $question->getCreatedAt());
|
self::assertInstanceOf('\DateTimeImmutable', $question->getCreatedAt());
|
||||||
self::assertEquals([], $question->getBadges());
|
self::assertEquals([], $question->getBadges());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user