Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
40.00% covered (danger)
40.00%
16 / 40
40.91% covered (danger)
40.91%
9 / 22
CRAP
0.00% covered (danger)
0.00%
0 / 1
Referentiel
40.00% covered (danger)
40.00%
16 / 40
40.91% covered (danger)
40.91%
9 / 22
184.46
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 __clone
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 deserialize
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 __toString
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDescription
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setDescription
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAuthorizedCollectivities
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAuthorizedCollectivities
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addAuthorizedCollectivity
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getOptionRightSelection
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setOptionRightSelection
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAuthorizedCollectivityTypes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAuthorizedCollectivityTypes
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDomains
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDomains
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMaturity
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setMaturity
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSurveys
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setSurveys
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
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
22declare(strict_types=1);
23
24namespace App\Domain\Maturity\Model;
25
26use App\Application\Traits\Model\HistoryTrait;
27use App\Domain\User\Model\Collectivity;
28use Doctrine\Common\Collections\ArrayCollection;
29use Doctrine\Common\Collections\Collection;
30use JMS\Serializer\Annotation as Serializer;
31use Ramsey\Uuid\Uuid;
32use Ramsey\Uuid\UuidInterface;
33
34class 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    /**
89     * @var \DateTimeImmutable|null
90     *
91     * @Serializer\Type("DateTimeImmutable")
92     */
93    private $createdAt;
94
95    /**
96     * @var \DateTimeImmutable|null
97     *
98     * @Serializer\Type("DateTimeImmutable")
99     */
100    private $updatedAt;
101
102    public function __construct()
103    {
104        $this->id                          = Uuid::uuid4();
105        $this->domains                     = new ArrayCollection();
106        $this->authorizedCollectivities    = new ArrayCollection();
107        $this->authorizedCollectivityTypes = new ArrayCollection();
108    }
109
110    public function __clone()
111    {
112        $this->id                       = null;
113        $this->authorizedCollectivities = null;
114
115        $domains = [];
116        foreach ($this->domains as $domain) {
117            $domains[] = clone $domain;
118        }
119
120        $this->domains = $domains;
121    }
122
123    public function deserialize(): void
124    {
125        $this->id = Uuid::uuid4();
126        foreach ($this->domains as $domain) {
127            $domain->deserialize();
128            $domain->setReferentiel($this);
129        }
130    }
131
132    public function __toString(): string
133    {
134        if (\is_null($this->getName())) {
135            return '';
136        }
137
138        if (\mb_strlen($this->getName()) > 150) {
139            return \mb_substr($this->getName(), 0, 150) . '...';
140        }
141
142        return $this->getName();
143    }
144
145    public function getId(): UuidInterface
146    {
147        return $this->id;
148    }
149
150    public function getName(): ?string
151    {
152        return $this->name;
153    }
154
155    public function setName(?string $name): void
156    {
157        $this->name = $name;
158    }
159
160    public function getDescription(): ?string
161    {
162        return $this->description;
163    }
164
165    public function setDescription(?string $description): void
166    {
167        $this->description = $description;
168    }
169
170    public function getAuthorizedCollectivities()
171    {
172        return $this->authorizedCollectivities;
173    }
174
175    public function setAuthorizedCollectivities($authorizedCollectivities): void
176    {
177        $this->authorizedCollectivities = $authorizedCollectivities;
178    }
179
180    public function addAuthorizedCollectivity(Collectivity $collectivity)
181    {
182        if ($this->authorizedCollectivities->contains($collectivity)) {
183            return;
184        }
185
186        $this->authorizedCollectivities[] = $collectivity;
187        $collectivity->addReferentiel($this);
188    }
189
190    public function getOptionRightSelection()
191    {
192        return $this->optionRightSelection;
193    }
194
195    public function setOptionRightSelection($optionRightSelection)
196    {
197        $this->optionRightSelection = $optionRightSelection;
198    }
199
200    public function getAuthorizedCollectivityTypes()
201    {
202        return $this->authorizedCollectivityTypes;
203    }
204
205    public function setAuthorizedCollectivityTypes(iterable $authorizedCollectivityTypes)
206    {
207        $this->authorizedCollectivityTypes = $authorizedCollectivityTypes;
208    }
209
210    public function getDomains()
211    {
212        return $this->domains;
213    }
214
215    public function setDomains($domains): void
216    {
217        $this->domains = $domains;
218    }
219
220    public function getMaturity()
221    {
222        return $this->maturity;
223    }
224
225    public function setMaturity(Maturity $maturity): void
226    {
227        $this->maturity = $maturity;
228    }
229
230    /**
231     * @return Survey[]|array
232     */
233    public function getSurveys(): array|Collection
234    {
235        return $this->surveys;
236    }
237
238    /**
239     * @param Survey[]|array $surveys
240     */
241    public function setSurveys(array $surveys): void
242    {
243        $this->surveys = $surveys;
244    }
245}