Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
30.77% |
12 / 39 |
|
42.86% |
9 / 21 |
CRAP | |
0.00% |
0 / 1 |
Domain | |
30.77% |
12 / 39 |
|
42.86% |
9 / 21 |
268.89 | |
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 | |||
getColor | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setColor | |
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 | |||
addQuestion | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setQuestions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQuestions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
addMaturity | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
removeMaturity | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getMaturity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getReferentiel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setReferentiel | |
100.00% |
1 / 1 |
|
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 JMS\Serializer\Annotation as Serializer; |
27 | use Ramsey\Uuid\Uuid; |
28 | use Ramsey\Uuid\UuidInterface; |
29 | |
30 | /** |
31 | * @Serializer\ExclusionPolicy("none") |
32 | */ |
33 | class Domain |
34 | { |
35 | /** |
36 | * @var UuidInterface |
37 | * |
38 | * @Serializer\Exclude |
39 | */ |
40 | private $id; |
41 | |
42 | private string $name; |
43 | |
44 | private ?string $description; |
45 | |
46 | private string $color; |
47 | |
48 | private int $position; |
49 | |
50 | /** |
51 | * @var Question[]|array |
52 | * |
53 | * @Serializer\Type("array<App\Domain\Maturity\Model\Question>") |
54 | */ |
55 | public $questions; |
56 | |
57 | /** |
58 | * @var iterable |
59 | * |
60 | * @Serializer\Exclude |
61 | */ |
62 | private $maturity; |
63 | |
64 | /** |
65 | * @var Referentiel |
66 | * |
67 | * @Serializer\Exclude |
68 | */ |
69 | private $referentiel; |
70 | |
71 | /** |
72 | * Domain constructor. |
73 | * |
74 | * @throws \Exception |
75 | */ |
76 | public function __construct() |
77 | { |
78 | $this->id = Uuid::uuid4(); |
79 | $this->questions = []; |
80 | $this->maturity = []; |
81 | } |
82 | |
83 | public function __clone() |
84 | { |
85 | $this->id = null; |
86 | $questions = []; |
87 | foreach ($this->questions as $question) { |
88 | $questions[] = clone $question; |
89 | } |
90 | $this->questions = $questions; |
91 | } |
92 | |
93 | public function deserialize(): void |
94 | { |
95 | $this->id = Uuid::uuid4(); |
96 | |
97 | foreach ($this->questions as $question) { |
98 | if ($question) { |
99 | $question->deserialize(); |
100 | $question->setDomain($this); |
101 | } |
102 | } |
103 | } |
104 | |
105 | public function __toString(): string |
106 | { |
107 | if (\is_null($this->getName())) { |
108 | return ''; |
109 | } |
110 | |
111 | if (\mb_strlen($this->getName()) > 150) { |
112 | return \mb_substr($this->getName(), 0, 150) . '...'; |
113 | } |
114 | |
115 | return $this->getName(); |
116 | } |
117 | |
118 | public function getId(): UuidInterface |
119 | { |
120 | return $this->id; |
121 | } |
122 | |
123 | public function getName(): ?string |
124 | { |
125 | return $this->name; |
126 | } |
127 | |
128 | public function setName(?string $name): void |
129 | { |
130 | $this->name = $name; |
131 | } |
132 | |
133 | public function getColor(): ?string |
134 | { |
135 | return $this->color; |
136 | } |
137 | |
138 | public function setColor(?string $color): void |
139 | { |
140 | $this->color = $color; |
141 | } |
142 | |
143 | public function getPosition(): ?int |
144 | { |
145 | return $this->position; |
146 | } |
147 | |
148 | public function setPosition(?int $position): void |
149 | { |
150 | $this->position = $position; |
151 | } |
152 | |
153 | public function addQuestion(Question $question) |
154 | { |
155 | $this->questions[] = $question; |
156 | $question->setDomain($this); |
157 | } |
158 | |
159 | public function setQuestions($questions) |
160 | { |
161 | $this->questions = $questions; |
162 | } |
163 | |
164 | public function getQuestions() |
165 | { |
166 | return $this->questions; |
167 | } |
168 | |
169 | public function addMaturity(Maturity $maturity) |
170 | { |
171 | $this->maturity = $maturity; |
172 | } |
173 | |
174 | public function removeMaturity(Maturity $maturity): void |
175 | { |
176 | $key = \array_search($maturity, $this->maturity, true); |
177 | |
178 | if (false === $key) { |
179 | return; |
180 | } |
181 | |
182 | unset($this->maturity[$key]); |
183 | } |
184 | |
185 | public function getMaturity(): iterable |
186 | { |
187 | return $this->maturity; |
188 | } |
189 | |
190 | public function getDescription(): ?string |
191 | { |
192 | return $this->description; |
193 | } |
194 | |
195 | public function setDescription(?string $description): void |
196 | { |
197 | $this->description = $description; |
198 | } |
199 | |
200 | public function getReferentiel(): Referentiel |
201 | { |
202 | return $this->referentiel; |
203 | } |
204 | |
205 | public function setReferentiel(Referentiel $referentiel): void |
206 | { |
207 | $this->referentiel = $referentiel; |
208 | } |
209 | } |