Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
45.16% covered (danger)
45.16%
14 / 31
58.82% covered (warning)
58.82%
10 / 17
CRAP
0.00% covered (danger)
0.00%
0 / 1
Survey
45.16% covered (danger)
45.16%
14 / 31
58.82% covered (warning)
58.82%
10 / 17
85.97
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
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addOptionalAnswer
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 setOptionalAnswers
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 removeOptionalAnswer
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getOptionalAnswers
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addMaturity
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 removeMaturity
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getMaturity
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMaturity
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getScore
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setScore
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getReferentiel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setReferentiel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAnswerSurveys
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAnswerSurveys
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
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
22declare(strict_types=1);
23
24namespace App\Domain\Maturity\Model;
25
26use App\Application\Traits\Model\CollectivityTrait;
27use App\Application\Traits\Model\CreatorTrait;
28use App\Application\Traits\Model\HistoryTrait;
29use App\Domain\Reporting\Model\LoggableSubject;
30use Ramsey\Uuid\Uuid;
31use Ramsey\Uuid\UuidInterface;
32
33class Survey implements LoggableSubject
34{
35    use CollectivityTrait;
36    use CreatorTrait;
37    use HistoryTrait;
38
39    /**
40     * @var UuidInterface
41     */
42    private $id;
43
44    private ?Referentiel $referentiel;
45
46    /**
47     * @var iterable|null
48     */
49    private $answerSurveys;
50
51    /**
52     * @var iterable|null
53     */
54    private $optionalAnswers;
55
56    /**
57     * @var iterable
58     */
59    private $maturity;
60
61    /**
62     * @var int
63     */
64    private $score;
65
66    /**
67     * Survey constructor.
68     *
69     * @throws \Exception
70     */
71    public function __construct()
72    {
73        $this->id            = Uuid::uuid4();
74        $this->answerSurveys = [];
75        $this->maturity      = [];
76        $this->score         = 0;
77    }
78
79    public function getId(): UuidInterface
80    {
81        return $this->id;
82    }
83
84    public function __toString(): string
85    {
86        return "Indice du {$this->createdAt->format('d/m/Y')}";
87    }
88
89    public function addOptionalAnswer(OptionalAnswer $answer): void
90    {
91        $this->optionalAnswers[] = $answer;
92        $answer->setSurvey($this);
93    }
94
95    public function setOptionalAnswers(iterable $answers): void
96    {
97        $this->optionalAnswers = $answers;
98    }
99
100    public function removeOptionalAnswer(OptionalAnswer $answer): void
101    {
102        $key = \array_search($answer, (array) $this->optionalAnswers, true);
103
104        if (false === $key) {
105            return;
106        }
107
108        unset($this->optionalAnswers[$key]);
109    }
110
111    public function getOptionalAnswers(): ?iterable
112    {
113        return $this->optionalAnswers;
114    }
115
116    public function addMaturity(Maturity $maturity): void
117    {
118        $this->maturity[] = $maturity;
119        $maturity->setSurvey($this);
120    }
121
122    public function removeMaturity(Maturity $maturity): void
123    {
124        $key = \array_search($maturity, (array) $this->maturity, true);
125
126        if (false === $key) {
127            return;
128        }
129
130        unset($this->maturity[$key]);
131    }
132
133    public function getMaturity(): iterable
134    {
135        return $this->maturity;
136    }
137
138    public function setMaturity(array $maturityList): void
139    {
140        $this->maturity = [];
141        foreach ($maturityList as $maturity) {
142            $this->maturity[] = $maturity;
143            $maturity->setSurvey($this);
144        }
145    }
146
147    public function getScore(): int
148    {
149        return $this->score;
150    }
151
152    public function setScore(int $score): void
153    {
154        $this->score = $score;
155    }
156
157    public function getReferentiel(): ?Referentiel
158    {
159        return $this->referentiel;
160    }
161
162    public function setReferentiel(?Referentiel $referentiel): void
163    {
164        $this->referentiel = $referentiel;
165    }
166
167    public function getAnswerSurveys(): ?iterable
168    {
169        return $this->answerSurveys;
170    }
171
172    public function setAnswerSurveys(?iterable $answerSurveys): void
173    {
174        $this->answerSurveys = $answerSurveys;
175    }
176}