Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
40.00% |
14 / 35 |
|
55.00% |
11 / 20 |
CRAP | |
0.00% |
0 / 1 |
Question | |
40.00% |
14 / 35 |
|
55.00% |
11 / 20 |
160.00 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
__clone | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
deserialize | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
__toString | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDomain | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setDomain | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAnswers | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPosition | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setPosition | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getWeight | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setWeight | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOptional | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setOptional | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOptionReason | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setOptionReason | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setAnswers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addAnswer | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of the MADIS - RGPD Management application. |
5 | * |
6 | * @copyright Copyright (c) 2018-2019 Soluris - Solutions Numériques Territoriales Innovantes |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU Affero General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU Affero General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Affero General Public License |
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | declare(strict_types=1); |
23 | |
24 | namespace App\Domain\Maturity\Model; |
25 | |
26 | use Doctrine\Common\Collections\ArrayCollection; |
27 | use JMS\Serializer\Annotation as Serializer; |
28 | use Ramsey\Uuid\Uuid; |
29 | use Ramsey\Uuid\UuidInterface; |
30 | |
31 | /** |
32 | * @Serializer\ExclusionPolicy("none") |
33 | */ |
34 | class Question |
35 | { |
36 | /** |
37 | * @var UuidInterface |
38 | * |
39 | * @Serializer\Exclude |
40 | */ |
41 | private $id; |
42 | |
43 | private string $name; |
44 | |
45 | private int $position; |
46 | |
47 | private int $weight; |
48 | |
49 | private bool $optional; |
50 | |
51 | private ?string $optionReason; |
52 | |
53 | /** |
54 | * @var Domain|null |
55 | * |
56 | * @Serializer\Exclude |
57 | */ |
58 | private $domain; |
59 | |
60 | /** |
61 | * @var Answer[]|array |
62 | * |
63 | * @Serializer\Type("array<App\Domain\Maturity\Model\Answer>") |
64 | */ |
65 | public $answers; |
66 | |
67 | /** |
68 | * Question constructor. |
69 | * |
70 | * @throws \Exception |
71 | */ |
72 | public function __construct() |
73 | { |
74 | $this->id = Uuid::uuid4(); |
75 | $this->answers = new ArrayCollection(); |
76 | $this->optionReason = null; |
77 | } |
78 | |
79 | public function __clone() |
80 | { |
81 | $this->id = null; |
82 | |
83 | $answers = []; |
84 | foreach ($this->answers as $answer) { |
85 | $answers[] = clone $answer; |
86 | } |
87 | $this->answers = $answers; |
88 | } |
89 | |
90 | public function deserialize(): void |
91 | { |
92 | $this->id = Uuid::uuid4(); |
93 | if (isset($this->answers)) { |
94 | foreach ($this->answers as $answer) { |
95 | $answer->deserialize(); |
96 | $answer->setQuestion($this); |
97 | } |
98 | } |
99 | } |
100 | |
101 | public function __toString(): string |
102 | { |
103 | if (\is_null($this->getName())) { |
104 | return ''; |
105 | } |
106 | |
107 | if (\mb_strlen($this->getName()) > 150) { |
108 | return \mb_substr($this->getName(), 0, 150) . '...'; |
109 | } |
110 | |
111 | return $this->getName(); |
112 | } |
113 | |
114 | public function getId(): UuidInterface |
115 | { |
116 | return $this->id; |
117 | } |
118 | |
119 | public function getName(): ?string |
120 | { |
121 | return $this->name; |
122 | } |
123 | |
124 | public function setName(?string $name): void |
125 | { |
126 | $this->name = $name; |
127 | } |
128 | |
129 | public function getDomain(): ?Domain |
130 | { |
131 | return $this->domain; |
132 | } |
133 | |
134 | public function setDomain(?Domain $domain): void |
135 | { |
136 | $this->domain = $domain; |
137 | } |
138 | |
139 | public function getAnswers(): ?iterable |
140 | { |
141 | return $this->answers; |
142 | } |
143 | |
144 | public function getPosition(): ?int |
145 | { |
146 | return $this->position; |
147 | } |
148 | |
149 | public function setPosition(?int $position): void |
150 | { |
151 | $this->position = $position; |
152 | } |
153 | |
154 | public function getWeight(): ?int |
155 | { |
156 | return $this->weight; |
157 | } |
158 | |
159 | public function setWeight(?int $weight): void |
160 | { |
161 | $this->weight = $weight; |
162 | } |
163 | |
164 | public function getOptional(): ?bool |
165 | { |
166 | return $this->optional; |
167 | } |
168 | |
169 | public function setOptional(?bool $optional): void |
170 | { |
171 | $this->optional = $optional; |
172 | } |
173 | |
174 | public function getOptionReason(): ?string |
175 | { |
176 | return $this->optionReason; |
177 | } |
178 | |
179 | public function setOptionReason(?string $optionReason): void |
180 | { |
181 | $this->optionReason = $optionReason; |
182 | } |
183 | |
184 | /** |
185 | * @param iterable|null $answers |
186 | */ |
187 | public function setAnswers(iterable|ArrayCollection|null $answers): void |
188 | { |
189 | $this->answers = $answers; |
190 | } |
191 | |
192 | public function addAnswer(Answer $answer): void |
193 | { |
194 | $this->answers[] = $answer; |
195 | $answer->setQuestion($this); |
196 | } |
197 | } |