Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
PublicConfiguration | |
0.00% |
0 / 37 |
|
0.00% |
0 / 12 |
420 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSavedConfiguration | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
setSavedConfiguration | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setType | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getMappedObject | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
__toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__get | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
__set | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
__call | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
_initMappedObject | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 |
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\Registry\Model; |
25 | |
26 | use App\Application\Traits\Model\HistoryTrait; |
27 | use Ramsey\Uuid\Uuid; |
28 | use Ramsey\Uuid\UuidInterface; |
29 | |
30 | /** |
31 | * Public Configuration / Choose what will be public or not. |
32 | */ |
33 | class PublicConfiguration |
34 | { |
35 | use HistoryTrait; |
36 | |
37 | public const bannedProperties = [ |
38 | Treatment::class => [ |
39 | 'id', |
40 | 'public', |
41 | 'createdAt', |
42 | 'updatedAt', |
43 | 'clonedFrom', |
44 | 'templateIdentifier', |
45 | 'template', |
46 | 'completion', |
47 | 'conformiteTraitement', |
48 | 'delay', |
49 | ], |
50 | ]; |
51 | |
52 | /** |
53 | * @var UuidInterface |
54 | */ |
55 | private $id; |
56 | |
57 | /** |
58 | * @var string |
59 | */ |
60 | private $savedConfiguration; |
61 | |
62 | /** |
63 | * @var \stdClass |
64 | */ |
65 | private $mappedObject; |
66 | |
67 | /** |
68 | * @var string |
69 | */ |
70 | private $type; |
71 | |
72 | /** |
73 | * PublicConfiguration constructor. |
74 | * |
75 | * @throws \Exception |
76 | */ |
77 | public function __construct(string $type) |
78 | { |
79 | $this->id = Uuid::uuid4(); |
80 | $this->savedConfiguration = ''; |
81 | $this->type = $type; |
82 | $this->_initMappedObject(); |
83 | } |
84 | |
85 | public function getId(): UuidInterface |
86 | { |
87 | return $this->id; |
88 | } |
89 | |
90 | public function getSavedConfiguration(): ?string |
91 | { |
92 | if (!$this->savedConfiguration) { |
93 | $this->savedConfiguration = json_encode($this->mappedObject); |
94 | } |
95 | |
96 | return $this->savedConfiguration; |
97 | } |
98 | |
99 | public function setSavedConfiguration(?string $savedConfiguration) |
100 | { |
101 | $this->savedConfiguration = $savedConfiguration; |
102 | |
103 | return $this; |
104 | } |
105 | |
106 | public function getType(): string |
107 | { |
108 | return $this->type; |
109 | } |
110 | |
111 | public function setType(string $type): self |
112 | { |
113 | $this->type = $type; |
114 | |
115 | return $this; |
116 | } |
117 | |
118 | public function getMappedObject(): \stdClass |
119 | { |
120 | if (!$this->mappedObject) { |
121 | $this->_initMappedObject(); |
122 | } |
123 | |
124 | return $this->mappedObject; |
125 | } |
126 | |
127 | public function __toString(): string |
128 | { |
129 | return $this->getSavedConfiguration(); |
130 | } |
131 | |
132 | public function __get(string $name) |
133 | { |
134 | if (!$this->mappedObject) { |
135 | $this->_initMappedObject(); |
136 | } |
137 | |
138 | if (property_exists($this->mappedObject, $name)) { |
139 | return $this->mappedObject->$name; |
140 | } |
141 | |
142 | return null; |
143 | } |
144 | |
145 | public function __set(string $name, $value) |
146 | { |
147 | if (!$this->mappedObject) { |
148 | $this->_initMappedObject(); |
149 | } |
150 | $this->mappedObject->$name = $value; |
151 | $this->savedConfiguration = json_encode($this->mappedObject); |
152 | } |
153 | |
154 | public function __call(string $name, $arguments) |
155 | { |
156 | return $this->__get($name); |
157 | } |
158 | |
159 | private function _initMappedObject() |
160 | { |
161 | if (!$this->mappedObject) { |
162 | $this->mappedObject = new \stdClass(); |
163 | $className = $this->type; |
164 | $entity = new $className(); |
165 | $reflection = new \ReflectionClass($entity); |
166 | $properties = $reflection->getProperties(); |
167 | |
168 | foreach ($properties as $property) { |
169 | $propertyName = $property->name; |
170 | |
171 | if (!in_array($propertyName, self::bannedProperties[$this->type])) { |
172 | $this->mappedObject->$propertyName = false; |
173 | } |
174 | } |
175 | } |
176 | } |
177 | } |