Completed
Pull Request — master (#17)
by Luc
06:00 queued 03:11
created

QuestionFormDTO::toQuestion()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 22
nc 1
nop 1
1
<?php
2
3
namespace VSV\GVQ_API\Question\Forms;
4
5
use League\Uri\Uri;
6
use Ramsey\Uuid\UuidFactoryInterface;
7
use Symfony\Component\HttpFoundation\File\UploadedFile;
8
use VSV\GVQ_API\Common\ValueObjects\Language;
9
use VSV\GVQ_API\Common\ValueObjects\NotEmptyString;
10
use VSV\GVQ_API\Question\Models\Answer;
11
use VSV\GVQ_API\Question\Models\Answers;
12
use VSV\GVQ_API\Question\Models\Category;
13
use VSV\GVQ_API\Question\Models\Question;
14
use VSV\GVQ_API\Question\ValueObjects\Year;
15
16
class QuestionFormDTO
17
{
18
    /**
19
     * @var Language
20
     */
21
    public $language;
22
23
    /**
24
     * @var int
25
     */
26
    public $year;
27
28
    /**
29
     * @var Category
30
     */
31
    public $category;
32
33
    /**
34
     * @var UploadedFile
35
     */
36
    public $photo;
37
38
    /**
39
     * @var string
40
     */
41
    public $answer1;
42
43
    /**
44
     * @var string
45
     */
46
    public $answer2;
47
48
    /**
49
     * @var string
50
     */
51
    public $answer3;
52
53
    /**
54
     * @var int
55
     */
56
    public $correctAnswer;
57
58
    /**
59
     * @var string
60
     */
61
    public $text;
62
63
    /**
64
     * @var string
65
     */
66
    public $feedback;
67
68
    /**
69
     * QuestionForm constructor.
70
     */
71
    public function __construct()
72
    {
73
        $this->year = 2018;
74
    }
75
76
    /**
77
     * @param UuidFactoryInterface $uuidFactory
78
     * @return Question
79
     */
80
    public function toQuestion(UuidFactoryInterface $uuidFactory): Question
81
    {
82
        // TODO: Take into account the correct number of answers, can be 2 or 3.
83
        $answers = new Answers(
84
            new Answer(
85
                $uuidFactory->uuid4(),
86
                new NotEmptyString($this->answer1),
87
                $this->correctAnswer === 1 ? true : false
88
            ),
89
            new Answer(
90
                $uuidFactory->uuid4(),
91
                new NotEmptyString($this->answer2),
92
                $this->correctAnswer === 2 ? true : false
93
            ),
94
            new Answer(
95
                $uuidFactory->uuid4(),
96
                new NotEmptyString($this->answer3),
97
                $this->correctAnswer === 3 ? true : false
98
            )
99
        );
100
101
        // TODO: Refactor picture Uri to filename.
102
        return new Question(
103
            $uuidFactory->uuid4(),
104
            $this->language,
105
            new Year($this->year),
106
            $this->category,
107
            new NotEmptyString($this->text),
108
            Uri::createFromString('http://localhost:8000/'),
109
            $answers,
110
            new NotEmptyString($this->feedback)
111
        );
112
    }
113
}
114