Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
40.00% |
16 / 40 |
|
40.91% |
9 / 22 |
CRAP | |
0.00% |
0 / 1 |
Referentiel | |
40.00% |
16 / 40 |
|
40.91% |
9 / 22 |
184.46 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
__clone | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
deserialize | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
__toString | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
3.07 | |||
getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setDescription | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAuthorizedCollectivities | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setAuthorizedCollectivities | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addAuthorizedCollectivity | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getOptionRightSelection | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setOptionRightSelection | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthorizedCollectivityTypes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setAuthorizedCollectivityTypes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDomains | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setDomains | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getMaturity | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setMaturity | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSurveys | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setSurveys | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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 App\Application\Traits\Model\HistoryTrait; |
27 | use App\Domain\User\Model\Collectivity; |
28 | use Doctrine\Common\Collections\ArrayCollection; |
29 | use Doctrine\Common\Collections\Collection; |
30 | use JMS\Serializer\Annotation as Serializer; |
31 | use Ramsey\Uuid\Uuid; |
32 | use Ramsey\Uuid\UuidInterface; |
33 | |
34 | class Referentiel |
35 | { |
36 | use HistoryTrait; |
37 | |
38 | /** |
39 | * @Serializer\Exclude |
40 | */ |
41 | private ?UuidInterface $id; |
42 | |
43 | private string $name; |
44 | private ?string $description; |
45 | |
46 | /** |
47 | * @var array|Domain[] |
48 | * |
49 | * @Serializer\Type("array<App\Domain\Maturity\Model\Domain>") |
50 | */ |
51 | private $domains; |
52 | |
53 | /** |
54 | * @var array|Survey[] |
55 | * |
56 | * @Serializer\Exclude |
57 | */ |
58 | private $surveys; |
59 | |
60 | /** |
61 | * @var Maturity |
62 | * |
63 | * @Serializer\Exclude |
64 | */ |
65 | private $maturity; |
66 | |
67 | /** |
68 | * @var Collection|Collectivity[] |
69 | * |
70 | * @Serializer\Exclude |
71 | */ |
72 | private $authorizedCollectivities; |
73 | |
74 | /** |
75 | * @see CollectivityTypeDictionary |
76 | * |
77 | * @Serializer\Exclude |
78 | */ |
79 | private ?iterable $authorizedCollectivityTypes; |
80 | |
81 | /** |
82 | * @see DuplicationTargetOptionDictionary |
83 | * |
84 | * @Serializer\Exclude |
85 | */ |
86 | private ?string $optionRightSelection = null; |
87 | |
88 | public function __construct() |
89 | { |
90 | $this->id = Uuid::uuid4(); |
91 | $this->domains = new ArrayCollection(); |
92 | $this->authorizedCollectivities = new ArrayCollection(); |
93 | $this->authorizedCollectivityTypes = new ArrayCollection(); |
94 | } |
95 | |
96 | public function __clone() |
97 | { |
98 | $this->id = null; |
99 | $this->authorizedCollectivities = null; |
100 | |
101 | $domains = []; |
102 | foreach ($this->domains as $domain) { |
103 | $domains[] = clone $domain; |
104 | } |
105 | |
106 | $this->domains = $domains; |
107 | } |
108 | |
109 | public function deserialize(): void |
110 | { |
111 | $this->id = Uuid::uuid4(); |
112 | foreach ($this->domains as $domain) { |
113 | $domain->deserialize(); |
114 | $domain->setReferentiel($this); |
115 | } |
116 | } |
117 | |
118 | public function __toString(): string |
119 | { |
120 | if (\is_null($this->getName())) { |
121 | return ''; |
122 | } |
123 | |
124 | if (\mb_strlen($this->getName()) > 150) { |
125 | return \mb_substr($this->getName(), 0, 150) . '...'; |
126 | } |
127 | |
128 | return $this->getName(); |
129 | } |
130 | |
131 | public function getId(): UuidInterface |
132 | { |
133 | return $this->id; |
134 | } |
135 | |
136 | public function getName(): ?string |
137 | { |
138 | return $this->name; |
139 | } |
140 | |
141 | public function setName(?string $name): void |
142 | { |
143 | $this->name = $name; |
144 | } |
145 | |
146 | public function getDescription(): ?string |
147 | { |
148 | return $this->description; |
149 | } |
150 | |
151 | public function setDescription(?string $description): void |
152 | { |
153 | $this->description = $description; |
154 | } |
155 | |
156 | public function getAuthorizedCollectivities() |
157 | { |
158 | return $this->authorizedCollectivities; |
159 | } |
160 | |
161 | public function setAuthorizedCollectivities($authorizedCollectivities): void |
162 | { |
163 | $this->authorizedCollectivities = $authorizedCollectivities; |
164 | } |
165 | |
166 | public function addAuthorizedCollectivity(Collectivity $collectivity) |
167 | { |
168 | if ($this->authorizedCollectivities->contains($collectivity)) { |
169 | return; |
170 | } |
171 | |
172 | $this->authorizedCollectivities[] = $collectivity; |
173 | $collectivity->addReferentiel($this); |
174 | } |
175 | |
176 | public function getOptionRightSelection() |
177 | { |
178 | return $this->optionRightSelection; |
179 | } |
180 | |
181 | public function setOptionRightSelection($optionRightSelection) |
182 | { |
183 | $this->optionRightSelection = $optionRightSelection; |
184 | } |
185 | |
186 | public function getAuthorizedCollectivityTypes() |
187 | { |
188 | return $this->authorizedCollectivityTypes; |
189 | } |
190 | |
191 | public function setAuthorizedCollectivityTypes(iterable $authorizedCollectivityTypes) |
192 | { |
193 | $this->authorizedCollectivityTypes = $authorizedCollectivityTypes; |
194 | } |
195 | |
196 | public function getDomains() |
197 | { |
198 | return $this->domains; |
199 | } |
200 | |
201 | public function setDomains($domains): void |
202 | { |
203 | $this->domains = $domains; |
204 | } |
205 | |
206 | public function getMaturity() |
207 | { |
208 | return $this->maturity; |
209 | } |
210 | |
211 | public function setMaturity(Maturity $maturity): void |
212 | { |
213 | $this->maturity = $maturity; |
214 | } |
215 | |
216 | /** |
217 | * @return Survey[]|array |
218 | */ |
219 | public function getSurveys(): array|Collection |
220 | { |
221 | return $this->surveys; |
222 | } |
223 | |
224 | /** |
225 | * @param Survey[]|array $surveys |
226 | */ |
227 | public function setSurveys(array $surveys): void |
228 | { |
229 | $this->surveys = $surveys; |
230 | } |
231 | } |