Completed
Pull Request — master (#1)
by Luc
04:53 queued 02:14
created

Question::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 8
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Question\Models;
4
5
use League\Uri\Interfaces\Uri;
6
use Ramsey\Uuid\UuidInterface;
7
use VSV\GVQ_API\Question\ValueObjects\Language;
8
use VSV\GVQ_API\Question\ValueObjects\NotEmptyString;
9
use VSV\GVQ_API\Question\ValueObjects\Year;
10
11
class Question
12
{
13
    /**
14
     * @var UuidInterface
15
     */
16
    private $id;
17
18
    /**
19
     * @var Language
20
     */
21
    private $language;
22
23
    /**
24
     * @var Year
25
     */
26
    private $year;
27
28
    /**
29
     * @var Category
30
     */
31
    private $category;
32
33
    /**
34
     * @var NotEmptyString
35
     */
36
    private $questionText;
37
38
    /**
39
     * @var Uri
40
     */
41
    private $pictureUri;
42
43
    /**
44
     * @var Answers
45
     */
46
    private $answers;
47
48
    /**
49
     * @var NotEmptyString
50
     */
51
    private $feedback;
52
53
    /**
54
     * @var \DateTimeImmutable
55
     */
56
    private $archivedOn;
57
58
    /**
59
     * @param UuidInterface $id
60
     * @param Language $language
61
     * @param Year $year
62
     * @param Category $category
63
     * @param NotEmptyString $questionText
64
     * @param Uri $pictureUri
65
     * @param Answers $answers
66
     * @param NotEmptyString $feedback
67
     */
68
    public function __construct(
69
        UuidInterface $id,
70
        Language $language,
71
        Year $year,
72
        Category $category,
73
        NotEmptyString $questionText,
74
        Uri $pictureUri,
75
        Answers $answers,
76
        NotEmptyString $feedback
77
    ) {
78
        $this->id = $id;
79
        $this->language = $language;
80
        $this->year = $year;
81
        $this->category = $category;
82
        $this->questionText = $questionText;
83
        $this->pictureUri = $pictureUri;
84
        $this->answers = $answers;
85
        $this->feedback = $feedback;
86
    }
87
88
    /**
89
     * @return UuidInterface
90
     */
91
    public function getId(): UuidInterface
92
    {
93
        return $this->id;
94
    }
95
96
    /**
97
     * @return Language
98
     */
99
    public function getLanguage(): Language
100
    {
101
        return $this->language;
102
    }
103
104
    /**
105
     * @return Year
106
     */
107
    public function getYear(): Year
108
    {
109
        return $this->year;
110
    }
111
112
    /**
113
     * @return Category
114
     */
115
    public function getCategory(): Category
116
    {
117
        return $this->category;
118
    }
119
120
    /**
121
     * @return NotEmptyString
122
     */
123
    public function getQuestionText(): NotEmptyString
124
    {
125
        return $this->questionText;
126
    }
127
128
    /**
129
     * @return Uri
130
     */
131
    public function getPictureUri(): Uri
132
    {
133
        return $this->pictureUri;
134
    }
135
136
    /**
137
     * @return Answers
138
     */
139
    public function getAnswers(): Answers
140
    {
141
        return $this->answers;
142
    }
143
144
    /**
145
     * @return NotEmptyString
146
     */
147
    public function getFeedback(): NotEmptyString
148
    {
149
        return $this->feedback;
150
    }
151
152
    /**
153
     * @param \DateTimeImmutable $archiveOn
154
     */
155
    public function archiveOn(\DateTimeImmutable $archiveOn): void
156
    {
157
        if ($this->archivedOn !== null) {
158
            throw new \DomainException(
159
                'The question with id: "'.$this->getId()->toString().'" was already archived.'
160
            );
161
        }
162
163
        $this->archivedOn = $archiveOn;
164
    }
165
166
    /**
167
     * @return bool
168
     */
169
    public function isArchived(): bool
170
    {
171
        return $this->archivedOn !== null;
172
    }
173
174
    /**
175
     * @return \DateTimeImmutable
176
     */
177
    public function getArchivedOn(): ?\DateTimeImmutable
178
    {
179
        return $this->archivedOn;
180
    }
181
}
182