AnswerEntity::getText()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Question\Repositories\Entities;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Ramsey\Uuid\Uuid;
7
use VSV\GVQ_API\Common\Repositories\Entities\Entity;
8
use VSV\GVQ_API\Question\Models\Answer;
9
use VSV\GVQ_API\Common\ValueObjects\NotEmptyString;
10
11
/**
12
 * @ORM\Entity()
13
 * @ORM\Table(name="answer")
14
 */
15
class AnswerEntity extends Entity
16
{
17
    /**
18
     * @var string
19
     *
20
     * @ORM\Column(type="string", length=1024, nullable=false)
21
     */
22
    private $text;
23
24
    /**
25
     * @var bool
26
     *
27
     * @ORM\Column(type="boolean", nullable=false)
28
     */
29
    private $correct;
30
31
    /**
32
     * @var QuestionEntity
33
     *
34
     * @ORM\ManyToOne(targetEntity="QuestionEntity", inversedBy="answerEntities")
35
     * @ORM\JoinColumn(name="question_id", referencedColumnName="id", nullable=false)
36
     */
37
    private $questionEntity;
38
39
    /**
40
     * @param string $id
41
     * @param string $text
42
     * @param bool $correct
43
     */
44
    private function __construct(
45
        string $id,
46
        string $text,
47
        bool $correct
48
    ) {
49
        parent::__construct($id);
50
51
        $this->text = $text;
52
        $this->correct = $correct;
53
    }
54
55
    /**
56
     * @param Answer $answer
57
     * @return AnswerEntity
58
     */
59
    public static function fromAnswer(Answer $answer): AnswerEntity
60
    {
61
        return new AnswerEntity(
62
            $answer->getId()->toString(),
63
            $answer->getText()->toNative(),
64
            $answer->isCorrect()
65
        );
66
    }
67
68
    /**
69
     * @return Answer
70
     */
71
    public function toAnswer(): Answer
72
    {
73
        return new Answer(
74
            Uuid::fromString($this->getId()),
75
            new NotEmptyString($this->getText()),
76
            $this->isCorrect()
77
        );
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getText(): string
84
    {
85
        return $this->text;
86
    }
87
88
    /**
89
     * @return bool
90
     */
91
    public function isCorrect(): bool
92
    {
93
        return $this->correct;
94
    }
95
96
    /**
97
     * @param QuestionEntity $questionEntity
98
     */
99
    public function setQuestionEntity(QuestionEntity $questionEntity): void
100
    {
101
        $this->questionEntity = $questionEntity;
102
    }
103
}
104