Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ClonerProvider | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
getCloner | |
100.00% |
9 / 9 |
|
100.00% |
1 / 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\Admin\Cloner; |
25 | |
26 | use App\Domain\Admin\Dictionary\DuplicationTypeDictionary; |
27 | |
28 | class ClonerProvider |
29 | { |
30 | /** |
31 | * @var ClonerInterface |
32 | */ |
33 | private $treatmentCloner; |
34 | |
35 | /** |
36 | * @var ClonerInterface |
37 | */ |
38 | private $contractorCloner; |
39 | |
40 | /** |
41 | * @var ClonerInterface |
42 | */ |
43 | private $mesurementCloner; |
44 | |
45 | /** |
46 | * @var ClonerInterface |
47 | */ |
48 | private $toolCloner; |
49 | |
50 | public function __construct( |
51 | ClonerInterface $treatmentCloner, |
52 | ClonerInterface $contractorCloner, |
53 | ClonerInterface $mesurementCloner, |
54 | ClonerInterface $toolCloner, |
55 | ) { |
56 | $this->treatmentCloner = $treatmentCloner; |
57 | $this->contractorCloner = $contractorCloner; |
58 | $this->mesurementCloner = $mesurementCloner; |
59 | $this->toolCloner = $toolCloner; |
60 | } |
61 | |
62 | /** |
63 | * Get cloner object thanks to type to clone. |
64 | */ |
65 | public function getCloner(string $type): ClonerInterface |
66 | { |
67 | switch ($type) { |
68 | case DuplicationTypeDictionary::KEY_TREATMENT: |
69 | return $this->treatmentCloner; |
70 | case DuplicationTypeDictionary::KEY_CONTRACTOR: |
71 | return $this->contractorCloner; |
72 | case DuplicationTypeDictionary::KEY_MESUREMENT: |
73 | return $this->mesurementCloner; |
74 | case DuplicationTypeDictionary::KEY_TOOL: |
75 | return $this->toolCloner; |
76 | default: |
77 | throw new \RuntimeException('The provided type ' . $type . ' is not a known one.'); |
78 | } |
79 | } |
80 | } |