Completed
Pull Request — master (#17)
by Luc
07:43 queued 04:45
created

QuestionFormDTO   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 94
rs 10
c 0
b 0
f 0

2 Methods

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