Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
15.38% covered (danger)
15.38%
12 / 78
38.10% covered (danger)
38.10%
8 / 21
CRAP
0.00% covered (danger)
0.00%
0 / 1
ConformiteTraitement
15.38% covered (danger)
15.38%
12 / 78
38.10% covered (danger)
38.10%
8 / 21
1690.15
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTraitement
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTraitement
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getReponses
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getReponseOfName
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
 addReponse
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 removeReponse
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getNbConformes
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setNbConformes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNbNonConformesMineures
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setNbNonConformesMineures
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNbNonConformesMajeures
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setNbNonConformesMajeures
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAnalyseImpacts
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getLastAnalyseImpact
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
20
 setAnalyseImpacts
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __toString
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getUpdatedBy
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setUpdatedBy
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getNeedsAipd
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 1
702
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\Registry\Model\ConformiteTraitement;
25
26use App\Application\Traits\Model\CreatorTrait;
27use App\Application\Traits\Model\HistoryTrait;
28use App\Domain\AIPD\Model\AnalyseImpact;
29use App\Domain\Registry\Model\Treatment;
30use App\Domain\Registry\Model\TreatmentDataCategory;
31use App\Domain\Reporting\Model\LoggableSubject;
32use Ramsey\Uuid\Uuid;
33use Ramsey\Uuid\UuidInterface;
34
35class ConformiteTraitement implements LoggableSubject
36{
37    use CreatorTrait;
38    use HistoryTrait;
39
40    /**
41     * @var UuidInterface
42     */
43    private $id;
44
45    /**
46     * @var Treatment
47     */
48    private $traitement;
49
50    /**
51     * @var iterable|Reponse[]
52     */
53    private $reponses;
54
55    /**
56     * @var int
57     */
58    private $nbConformes;
59
60    /**
61     * @var int
62     */
63    private $nbNonConformesMineures;
64
65    /**
66     * @var int
67     */
68    private $nbNonConformesMajeures;
69
70    /**
71     * @var array|AnalyseImpact[]
72     */
73    private $analyseImpacts;
74
75    /**
76     * @var string|null
77     */
78    private $updatedBy;
79
80    public function __construct()
81    {
82        $this->id                     = Uuid::uuid4();
83        $this->reponses               = [];
84        $this->nbConformes            = 0;
85        $this->nbNonConformesMineures = 0;
86        $this->nbNonConformesMajeures = 0;
87    }
88
89    public function getId(): UuidInterface
90    {
91        return $this->id;
92    }
93
94    public function getTraitement(): Treatment
95    {
96        return $this->traitement;
97    }
98
99    public function setTraitement(Treatment $traitement): void
100    {
101        $this->traitement = $traitement;
102    }
103
104    /**
105     * @return iterable|Reponse[]
106     */
107    public function getReponses(): iterable
108    {
109        return $this->reponses;
110    }
111
112    public function getReponseOfName(string $name): ?Reponse
113    {
114        foreach ($this->reponses as $reponse) {
115            if ($reponse->getQuestion()->getQuestion() === $name) {
116                return $reponse;
117            }
118        }
119
120        return null;
121    }
122
123    public function addReponse(Reponse $reponse): void
124    {
125        $this->reponses[] = $reponse;
126        $reponse->setConformiteTraitement($this);
127    }
128
129    public function removeReponse(Reponse $reponse): void
130    {
131        $key = \array_search($reponse, $this->reponses, true);
132
133        if (false === $key) {
134            return;
135        }
136
137        unset($this->reponses[$key]);
138    }
139
140    public function getNbConformes(): int
141    {
142        return $this->nbConformes;
143    }
144
145    public function setNbConformes(int $nbConformes): void
146    {
147        $this->nbConformes = $nbConformes;
148    }
149
150    public function getNbNonConformesMineures(): int
151    {
152        return $this->nbNonConformesMineures;
153    }
154
155    public function setNbNonConformesMineures(int $nbNonConformesMineures): void
156    {
157        $this->nbNonConformesMineures = $nbNonConformesMineures;
158    }
159
160    public function getNbNonConformesMajeures(): int
161    {
162        return $this->nbNonConformesMajeures;
163    }
164
165    public function setNbNonConformesMajeures(int $nbNonConformesMajeures): void
166    {
167        $this->nbNonConformesMajeures = $nbNonConformesMajeures;
168    }
169
170    public function getAnalyseImpacts()
171    {
172        return $this->analyseImpacts;
173    }
174
175    public function getLastAnalyseImpact(): ?AnalyseImpact
176    {
177        /** @var AnalyseImpact|null $return */
178        $return = null;
179        foreach ($this->analyseImpacts as $analyseImpact) {
180            if (null === $return || $return->getDateValidation() < $analyseImpact->getDateValidation()) {
181                $return = $analyseImpact;
182            }
183        }
184
185        return $return;
186    }
187
188    public function setAnalyseImpacts($analyseImpacts): void
189    {
190        $this->analyseImpacts = $analyseImpacts;
191    }
192
193    public function __toString(): string
194    {
195        return $this->traitement->__toString();
196    }
197
198    public function getUpdatedBy(): ?string
199    {
200        return $this->updatedBy;
201    }
202
203    public function setUpdatedBy(?string $updatedBy): void
204    {
205        $this->updatedBy = $updatedBy;
206    }
207
208    /**
209     * This returns true if the current treatment needs an AIPD to be done.
210     */
211    public function getNeedsAipd(): bool
212    {
213        $treatment = $this->getTraitement();
214
215        $doneAipds = 0;
216        /** @var AnalyseImpact $aipd */
217        foreach ($this->getAnalyseImpacts() as $aipd) {
218            if ('non_realisee' !== $aipd->getStatut() && 'en_cours' !== $aipd->getStatut()) {
219                ++$doneAipds;
220            }
221        }
222
223        if ($doneAipds) {
224            // Already has AIPD
225            return false;
226        }
227        if ($treatment->isExemptAIPD()) {
228            // Treatment is exempted
229            return false;
230        }
231        if (
232            $treatment->isLargeScaleCollection()
233            || $treatment->isDataCrossing()
234            || $treatment->isAutomatedDecisionsWithLegalEffect()
235            || $treatment->isEvaluationOrRating()
236            || $treatment->isAutomaticExclusionService()
237            || $treatment->isVulnerablePeople()
238            || $treatment->isSystematicMonitoring()
239            || $treatment->isInnovativeUse()
240        ) {
241            $sensitiveCount = 0;
242            $specificCount  = 0;
243            if ($treatment->isLargeScaleCollection()) {
244                ++$specificCount;
245            }
246            if ($treatment->isDataCrossing()) {
247                ++$specificCount;
248            }
249            if ($treatment->isAutomatedDecisionsWithLegalEffect()) {
250                ++$specificCount;
251            }
252            if ($treatment->isEvaluationOrRating()) {
253                ++$specificCount;
254            }
255            if ($treatment->isAutomaticExclusionService()) {
256                ++$specificCount;
257            }
258            if ($treatment->isVulnerablePeople()) {
259                ++$specificCount;
260            }
261            if ($treatment->isSystematicMonitoring()) {
262                ++$specificCount;
263            }
264            if ($treatment->isInnovativeUse()) {
265                ++$specificCount;
266            }
267            if ($specificCount > 1) {
268                return true;
269            }
270            // If one of these items is true, check if there are sensitive data categories
271            /** @var TreatmentDataCategory $cat */
272            foreach ($treatment->getDataCategories() as $cat) {
273                if ($cat->isSensible()) {
274                    ++$sensitiveCount;
275                    if ($sensitiveCount > 0) {
276                        return true;
277                    }
278                }
279            }
280        }
281
282        return false;
283    }
284}