Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MoreInfoTransformer | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
transform | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
reverseTransform | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
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\User\Form\DataTransformer; |
25 | |
26 | use Symfony\Component\Form\DataTransformerInterface; |
27 | use Symfony\Component\Form\Exception\TransformationFailedException; |
28 | |
29 | class MoreInfoTransformer implements DataTransformerInterface |
30 | { |
31 | /** |
32 | * Transform MoreInfo given as array to string value. |
33 | * |
34 | * @param array $value The array of moreInfos |
35 | * |
36 | * @return string|null The parsed array to string |
37 | */ |
38 | public function transform($value): ?string |
39 | { |
40 | if (\is_null($value)) { |
41 | return null; |
42 | } |
43 | |
44 | if (!\is_array($value)) { |
45 | throw new TransformationFailedException("Value of type array expected, '{$value}' given"); |
46 | } |
47 | |
48 | return \implode(', ', $value); |
49 | } |
50 | |
51 | /** |
52 | * Transform MoreInfo given as string to array value. |
53 | * |
54 | * @param mixed $value The string of moreInfos |
55 | * |
56 | * @return array The parsed string to array |
57 | */ |
58 | public function reverseTransform($value): array |
59 | { |
60 | if (\is_null($value)) { |
61 | return []; |
62 | } |
63 | |
64 | return [$value]; |
65 | } |
66 | } |